/*[[ Name := Stochastic Multi Chart Author := myfx Link := http:myfx Notes := Update on every tick := Yes Enable Alerts := Yes Disable alert once hit := No Lots := 1 Stop Loss := 500 Take Profit := 500 Trailing Stop := 10 ]]*/ defines: minprofit(0); var: cnt(0),current(0); var: ichyFileName(" "),ichyFile(0); var: messageB(" "),Bar(0); var: message5(" "); var: message15(" "); var: message30(" "); var: message60(" "); var: message240(" "); var: uLote(0),meLote(0),compound(0); meLote = Floor(Lots); if compound = 1 then { If FreeMargin/2/1000 > 200 Then { uLote=200; } Else { uLote = FreeMargin/2/1000; }; meLote = Floor(uLote); }; if IsGlobalVariable(AccountNumber +"_"+ Symbol + 5 + "_stockastic") then { if getGlobalVariable(AccountNumber +"_"+ Symbol + 5 + "_stockastic") =1 then message5= "buy"; if getGlobalVariable(AccountNumber +"_"+ Symbol + 5 + "_stockastic") =2 then message5= "sell"; if getGlobalVariable(AccountNumber +"_"+ Symbol + 5 + "_stockastic") =3 then message5= "neither"; } else { message5 = "No 5 minute chart data"; }; if IsGlobalVariable(AccountNumber +"_"+ Symbol + 15 + "_stockastic") then { if getGlobalVariable(AccountNumber +"_"+ Symbol + 15 + "_stockastic") =1 then message15= "buy"; if getGlobalVariable(AccountNumber +"_"+ Symbol + 15 + "_stockastic") =2 then message15= "sell"; if getGlobalVariable(AccountNumber +"_"+ Symbol + 15 + "_stockastic") =3 then message15= "neither"; } else { message15 = "No 15 minute chart data"; }; if IsGlobalVariable(AccountNumber +"_"+ Symbol + 30 + "_stockastic") then { if getGlobalVariable(AccountNumber +"_"+ Symbol + 30 + "_stockastic") =1 then message30= "buy"; if getGlobalVariable(AccountNumber +"_"+ Symbol + 30 + "_stockastic") =2 then message30= "sell"; if getGlobalVariable(AccountNumber +"_"+ Symbol + 30 + "_stockastic") =3 then message30= "neither"; } else { message30 = "No 30 minute chart data"; }; if IsGlobalVariable(AccountNumber +"_"+ Symbol + 60 + "_stockastic") then { if getGlobalVariable(AccountNumber +"_"+ Symbol + 60 + "_stockastic") =1 then message60= "buy"; if getGlobalVariable(AccountNumber +"_"+ Symbol + 60 + "_stockastic") =2 then message60= "sell"; if getGlobalVariable(AccountNumber +"_"+ Symbol + 60 + "_stockastic") =3 then message60= "neither"; } else { message60 = "No 60 minute chart data"; }; if IsGlobalVariable(AccountNumber +"_"+ Symbol + 240 + "_stockastic") then { if getGlobalVariable(AccountNumber +"_"+ Symbol + 240 + "_stockastic") =1 then message240= "buy"; if getGlobalVariable(AccountNumber +"_"+ Symbol + 240 + "_stockastic") =2 then message240= "sell"; if getGlobalVariable(AccountNumber +"_"+ Symbol + 240 + "_stockastic") =3 then message240= "neither"; } else { message240 = "No 240 minute chart data"; }; Comment("5 Min ",message5," 15 Min ",message15," 30 Min ",message30," 60 Min ",message60," 240 Min ",message240); if (iSTO(5,3,3,MODE_SMA,MODE_MAIN,1) > iSTO(5,3,3,MODE_SMA,MODE_SIGNAL,1)) Then { messageB="buy"; if not IsGlobalVariable(AccountNumber +"_"+ Symbol + Period + "_stockastic") then { setGlobalVariable(AccountNumber +"_"+ Symbol + Period + "_stockastic",1); } else { setGlobalVariable(AccountNumber +"_"+ Symbol + Period + "_stockastic",1); }; }; if (iSTO(5,3,3,MODE_SMA,MODE_MAIN,1) < iSTO(5,3,3,MODE_SMA,MODE_SIGNAL,1)) Then { messageB="sell"; if not IsGlobalVariable(AccountNumber +"_"+ Symbol + Period + "_stockastic") then { setGlobalVariable(AccountNumber +"_"+ Symbol + Period + "_stockastic",2); } else { setGlobalVariable(AccountNumber +"_"+ Symbol + Period + "_stockastic",2); }; }; if messageB !="buy" and messageB !="sell" then { messageB="Conditions not met " + AccountNumber; setGlobalVariable(AccountNumber +"_"+ Symbol + Period + "_stockastic",3); }; If TotalTrades>0 then { Print ("Open Trade"); for cnt = 1 to TotalTrades Begin If Ord(cnt,VAL_TYPE)=OP_SELL then { if (message30 = "buy") then { CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Ask,3,Violet); // Print("Woulda closed here"); }; }; If Ord(cnt,VAL_TYPE)=OP_BUY then { if (message30 = "sell") then { // Print("Woulda closed here"); CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Bid,3,Violet); }; }; end; }; If TotalTrades<1 then { If FreeMargin < 1000 then {Exit;}; if ((message5 = "sell" & message15 = "sell" & message30 = "sell" & message60 = "sell" & message240 = "sell" )) Then { SetArrow(time[0]+(Period), Ask, 490,Yellow); SetOrder(OP_SELL,meLote,BId,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,gold); Exit; }; if ((message5 = "buy" & message15 = "buy" & message30 = "buy" & message60 = "buy" & message240 = "buy" )) Then { SetArrow(time[0]+(Period), Ask, 489,Beige); SetOrder(OP_BUY,meLote,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,White); Exit; }; }; ///////////////Allow For Attachment to more than one Chart If TotalTrades > 0 then { Current = 0; for cnt = 1 to TotalTrades Begin If Not Ord(cnt,VAL_SYMBOL) = Symbol then { Current = Current+1; }; End; If Current = TotalTrades then { //put trading logic here If FreeMargin < 1000 then {Exit;}; if ((iSTO(5,3,3,MODE_SMA,MODE_MAIN,1) < iSTO(5,3,3,MODE_SMA,MODE_SIGNAL,1) & message5 = "sell" & message15 = "sell" & message30 = "sell" & message60 = "sell" & message240 = "sell" )) Then { SetArrow(time[0]+(Period), Ask, 490,Yellow); SetOrder(OP_SELL,meLote,BId,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,gold); Exit; }; if ((iSTO(5,3,3,MODE_SMA,MODE_MAIN,1) > iSTO(5,3,3,MODE_SMA,MODE_SIGNAL,1) & message5 = "buy" & message15 = "buy" & message30 = "buy" & message60 = "buy" & message240 = "buy" )) Then { SetArrow(time[0]+(Period), Ask, 489,Beige); SetOrder(OP_BUY,meLote,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,White); Exit; }; }; ///////////End Allow for more than one currency }; ////////////////////////////////////////////////////////// /////////////////////////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 + minprofit*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 - minprofit*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; };