/*[[ Name :=probability Author := FAB4X Link := Notes := RUN A 15 OR 30MIN CHART. Lots := 1.00 Stop Loss :=25 Take Profit := 50 Trailing Stop := 11 ]]*/ ///////////////////////////////////////////////////// // Defines ///////////////////////////////////////////////////// Defines: Slippage(3), BreakEvenSL(11); // Slippage Defines: TradesPerCurrency(1); // Number of lots to trade DEFINES: StopYear(2005),StopMonth(1); DEFINES: Start_Time(15),End_Time(20); Defines: barn(100),Length(6),Step(10); ///////////////////////////////////////////////////// // Variables ///////////////////////////////////////////////////// var: OpenSell(0); // Sell Trades Counter var: OpenBuy(0); // Buy Trades Counter var: PriceOpen(0); // Price Open var: I(0),cnt(0),vTime(0); // Misc Counter var: Mode(0); // Squirl the Mode variable for multiple use VAR: D1(0),D2(0),D3(0),D4(0),D5(0),DATA2(0),DATA5(0),PREDICT(0); Variables : shift(0),lasthigh(-1),lastlow(-1),lasthighpos(0),lastlowpos(0),currentvalue(0),lastvalue(0); Variables : val(0),back(0),res(0),flag(0); Variables : curlow(0),curhigh(0),currentshift(0),lastshift(0); Variable: Trend(0), lastposition(""), probability(0); Variable : LL(0),HH(0),Swing(0),Swing_n(0),BH(0),BL(0),zu(0),zd(0),NH(0),NL(0),uzl(0),SL(0); Array: Uzel[10000,3](0); ///////////////////////////////////////////////// // Main Script Conditions ///////////////////////////////////////////////// If Curtime - LastTradeTime < 11 then Exit; If FreeMargin < 500 then Exit; if year < 2005 then exit; //if month < StopMonth and year <> 2005 then exit; //If (DayOfWeek <2 or DayOfWeek >6 or hour < Start_Time or hour > End_Time) then exit; ///////////////////////////////////////////////////// // Calculations / Setting Values ///////////////////////////////////////////////////// OpenSell = 0; OpenBuy = 0; for I = 1 to TotalTrades { Mode = ord(I, VAL_TYPE); if ord(I, VAL_SYMBOL) == Symbol then { //Calculates how many Sell we have for the current Symbol if Mode == OP_SELL then { OpenSell++; }; //Calculates how many Buy we have for the current Symbol if Mode == OP_BUY then { OpenBuy++; }; }; }; ///////////////////////////////////////////////// // CUSTOM INDICATORS ///////////////////////////////////////////////// SetLoopCount(0); // loop from first bar to current bar (with shift=0) Swing_n=0;Swing=0;uzl=0; BH =High[barn];BL=Low[barn];zu=barn;zd=barn; For shift= barn downto 0 Begin LL=10000000;HH=-100000000; for i=shift+Length downto shift+1 Begin if Low[i]< LL then {LL=Low[i];}; if High[i]>HH then {HH=High[i];}; end; if Low[shift]HH then { Swing=2; if Swing_n=1 then {zu=shift+1;}; if Swing_n=-1 then {zd=shift+1;}; } else { if Low[shift]HH then {Swing=1;}; }; if Swing <> Swing_n and Swing_n<>0 then { if Swing=2 then {swing=-Swing_n;BH = High[shift];BL = Low[shift]; }; uzl=uzl+1; if swing = 1 then {Uzel[uzl,1]=zd;Uzel[uzl,2]=BL;Uzel[uzl,3]=shift;}; if swing =- 1 then {Uzel[uzl,1]=zu;Uzel[uzl,2]=BH;Uzel[uzl,3]=shift;}; BH = High[shift];BL = Low[shift]; }; if swing = 1 then { if High[shift] >= BH then {BH=High[shift];zu=shift;};}; if swing = -1 then { if Low[shift]<=BL then {BL=Low[shift]; zd=shift;};}; Swing_n=Swing; end; //for i =1 to uzl Begin //SetIndexValue(Uzel[i,1],Uzel[i,2]); //end ; // ниже торгующий довесок от eugene5 if High[0] - (HH+LL)/2 > (HH+LL)/2 - Low[0] then probability = ((High[0] - (HH+LL)/2) / ((HH-LL)/2)) * 100 else probability = - (((HH+LL)/2 - Low[0]) / ((HH-LL)/2)) * 100; ///////////////////////////////////////////////// // Comment on the chart ///////////////////////////////////////////////// IF probability > 0 THEN { comment(" TRADE STRENGTH IS ",probability ," % STRONGER FOR LONG POSITION "); } IF probability < 0 THEN { comment(" TRADE STRENGTH IS ",probability ," % STRONGER FOR SHORT POSITION "); } ///////////////////////////////////////////////// // Long/Short Entry and Re-entry Trades ///////////////////////////////////////////////// If OpenBuy < TradesPerCurrency then { IF probability > 100 THEN { Alert(Symbol, " BUY ALERT. Buy at ", PRICEASK , " or better."); //comment(" TRADE PREDICTION IS UP NOW ",probability ," %"); SetOrder(OP_BUY, Lots,ASK, Slippage,ASK-STOPLOSS*POINT ,ASK+TakeProfit * Point , BLUE); Exit; }; }; If OpenSell < TradesPerCurrency then { IF probability < -100 THEN { Alert(Symbol, " SELL ALERT. Sell at ", PRICEBID , " or better."); // comment(" TRADE PREDICTION IS DOWN NOW ",probability, " %" ); SetOrder(OP_SELL, Lots,BID, Slippage,BID+STOPLOSS*POINT,BID-TakeProfit * Point, RED); Exit; }; }; ///////////////////////////////////////////////// // Trade Management ///////////////////////////////////////////////// for I = 1 to TotalTrades { Mode = ord(I, VAL_TYPE); if ord(I, VAL_SYMBOL) == Symbol then { If OpenBuy > 0 then { IF probability < -100 then { Alert("TREND CHANGE *** Closing order at market for " + Symbol + " on " + Period + " Period."); CloseOrder(ord(I, VAL_TICKET), ord(I, VAL_LOTS), PRICEBID, Slippage, Orange); Exit; }; // // If 10 pips profit, move Stop to BreakEven if PRICEBID - ord(I, VAL_OPENPRICE) >= BreakEvenSL * Point and ord(I, VAL_STOPLOSS) < ord(I, VAL_OPENPRICE)) then { ModifyOrder(ord(I, VAL_TICKET), ord(I, VAL_OPENPRICE), ord(I, VAL_OPENPRICE), ord(I, VAL_TAKEPROFIT), Cyan); Exit; }; // PSAR Stop...MOVING TRAILING STOP // if psar > psar2 and ord(I, VAL_STOPLOSS) != psar and (Bid - psar) and (psar < Bid) then // { // ModifyOrder(ord(I, VAL_TICKET), ord(I, VAL_OPENPRICE), psar, ord(I, VAL_TAKEPROFIT), BlueViolet); // Exit; // }; }; If OpenSell > 0 then { IF probability > 100 then { Alert("TREND CHANGE *** Closing order at market for " + Symbol + " on " + Period + " Period."); CloseOrder(ord(I, VAL_TICKET), ord(I, VAL_LOTS), PRICEASK, Slippage, Orange); Exit; }; // // If 10 pips profit, move Stop to BreakEven if ord(I, VAL_OPENPRICE) - PRICEASK >= BreakEvenSL * Point and ord(I, VAL_STOPLOSS) > ord(I, VAL_OPENPRICE)) then { ModifyOrder(ord(I, VAL_TICKET), ord(I, VAL_OPENPRICE), ord(I, VAL_OPENPRICE), ord(I, VAL_TAKEPROFIT), Cyan); Exit; }; // Psar Stop...MOVING TRAILING STOP // if (psar < psar2) and (ord(i, VAL_STOPLOSS) != psar) and (psar - Ask ) and (psar > Ask) then // { // ModifyOrder(ord(I, VAL_TICKET), ord(I, VAL_OPENPRICE), psar , ord(I, VAL_TAKEPROFIT), BlueViolet); // Exit; // }; }; // }; }; ////////////////////////////////////////////////////////// /////////////////////////Trailing Stop Code ///////////////////// ////////////////////////////////////////////////////////// If TotalTrades > 0 then { for cnt = 1 to TotalTrades Begin If Ord(cnt,VAL_TYPE)=OP_BUY then { /////////////////// If Ord(cnt,VAL_SYMBOL)= Symbol then { If Ord(cnt,VAL_OPENPRICE) + TrailingStop*Point < Bid Then { If Ord(cnt,VAL_STOPLOSS)<(Bid-TrailingStop*Point) then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE), Bid-TrailingStop*Point,Ord(cnt,VAL_TAKEPROFIT),Red); Exit; }; }; If Ord(cnt,VAL_TAKEPROFIT) = 0 Then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE), Ord(cnt,VAL_OPENPRICE)-StopLoss*Point,Ord(cnt,VAL_OPENPRICE)+TakeProfit*Point,Red); Exit; }; }; };// End of BUY If Ord(cnt,VAL_TYPE)=OP_SELL then { /////////////////// If Ord(cnt,VAL_SYMBOL)= Symbol then { If Ord(cnt,VAL_OPENPRICE) - TrailingStop*Point > Ask Then { If Ord(cnt,VAL_STOPLOSS)>(Ask+TrailingStop*Point) then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE),Ask+TrailingStop*Point, Ord(cnt,VAL_TAKEPROFIT),White); Exit; }; }; If Ord(cnt,VAL_TAKEPROFIT) = 0 Then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE), Ord(cnt,VAL_OPENPRICE)+StopLoss*Point,Ord(cnt,VAL_OPENPRICE)-TakeProfit*Point,Red); Exit; }; }; };//End of Sell End; };