/*[[ Name := Scalping model Author := Copyright © 2004, MetaQuotes Software Corp. Link := http://www.metaquotes.net/ Notes := Lots := 1.00 Stop Loss := 30 Take Profit := 999 Trailing Stop := 30 ]]*/ Define: step(0.04); Define: maximum(0.2); Define: slippage(5); Define: risk(20); Define: mm(1); Define: Allow_partial_lots(0); Var: globalVarName1(""); Var: globalVarName2(""); Var: globalVarName3(""); Var: globalVarName4(""); Var: globalVarName5(""); Var: globalVarName6(""); Var: lotsi(0); Var: StK(0); Var: StD(0); Var: StKprev(0); Var: StDprev(0); Var: StK15min(0); Var: StD15min(0); Var: McClhist15min(0); Var: h115min(0); Var: i(0); Var: x(0); Var: y(0); Var: cnt(0); Var: Trailing_point(0); Var: McClHist(0); Var: Mcclelan(0.0001); Var: criteria(1); Var: MA1(0); Var: MA2(0); Var: debug(0); if Year >= 9 and Month > 8 then { Exit; } else { if Year >= 4 and Month == 8 and Day > 30 then Exit; } globalVarName1 = Symbol + "StK1min"; globalVarName2 = Symbol + "StD1min"; globalVarName3 = Symbol + Day + Hour + 15 * Floor(Minute / 15) + "K"; globalVarName4 = Symbol + Day + Hour + 15 * Floor(Minute / 15) + "D"; globalVarName5 = Symbol + Day + Hour + 15 * Floor(Minute / 15) + "h1"; globalVarName6 = Symbol + Day + Hour + 15 * Floor(Minute / 15) + "McClHist"; MA1 = iMA(3,1,0); MA2 = iMA(17,1,0); StK = iSTO(12,3,3,1,0,0); StD = iSTO(12,3,3,1,1,0); StKprev = iSTO(12,3,3,1,0,1); StDprev = iSTO(12,3,3,1,1,1); x = Ask - StopLoss * Point; y = Bid + StopLoss * Point; SetGlobalVariable(globalVarName1,StK); Comment(globalVarName1," : ",GetGlobalVariable(globalVarName1)); SetGlobalVariable(globalVarName2,StD); Comment(globalVarName2," : ",GetGlobalVariable(globalVarName2)); if not(IsGlobalVariable(globalVarName3)) or not(IsGlobalVariable(globalVarName4)) or not(IsGlobalVariable(globalVarName5)) or not(IsGlobalVariable(globalVarName6)) then { Print(" Run Backtest on 5min chart ......"); Exit; } StK15min = GetGlobalVariable(globalVarName3); StD15min = GetGlobalVariable(globalVarName4); h115min = GetGlobalVariable(globalVarName5); McClhist15min = GetGlobalVariable(globalVarName6); if mm != 0 then { if Allow_partial_lots == 0 then lotsi = Floor(Ceil(Equity * risk / 4000) / 10) else lotsi = Ceil(Equity * risk / 4000) / 10; if lotsi > 100 then lotsi = 100; } else { lotsi = Lots; } if TrailingStop < 10 then { Print("Invalid trailing stop"); Exit; } for cnt = 1 to TotalTrades { if Ord(cnt,VAL_TYPE) == OP_SELL then { if Bid - TrailingStop * Point < Trailing_point then Trailing_point = Ask - TrailingStop * Point; if Bid - Ord(cnt,VAL_OPENPRICE) < TrailingStop * Point then { if Ord(cnt,VAL_STOPLOSS) > Bid - TrailingStop * Point or Ord(cnt,VAL_STOPLOSS) == 0 then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE),Bid - TrailingStop * Point,Ord(cnt,VAL_TAKEPROFIT),Magenta); } } } if Ord(cnt,VAL_TYPE) == OP_BUY then { if Ask + TrailingStop * Point > Trailing_point then Trailing_point = Ask + TrailingStop * Point; if Ord(cnt,VAL_OPENPRICE) - Ask < TrailingStop * Point then { if Ord(cnt,VAL_STOPLOSS) < Ask + TrailingStop * Point or Ord(cnt,VAL_STOPLOSS) == 0 then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE),Ask + TrailingStop * Point,Ord(cnt,VAL_TAKEPROFIT),Magenta); } } } } if (criteria == 1 and ((StK > StD and Ceil(StK) < 50) or (StK15min > StD15min and StK15min < 50))) or (criteria == 2 and h115min == 1) then { for i = 1 to TotalTrades { if Ord(i,VAL_TYPE) == OP_BUY and OrderValue(i,VAL_SYMBOL) == Symbol then { if debug == 1 then { Print("!!!! Closing Open BUY: ","Criteria: ",criteria," ","day: ",Day," ","hr: ",Hour," ","mi: "," ",Minute," ","stk15min: "," ",StK15min," ","StD15min: ",StD15min," ","h115min:",h115min); Print("!!!! Closing Open BUY: ","Stk: ",StK," ","StD: ",StD," ","PSar: ",iSAR(step,maximum,0)," ","High: ",High[0]," ","Low: ",Low[0]); } CloseOrder(Ord(i,VAL_TICKET),Ord(i,VAL_LOTS),Bid,slippage,White); SetArrow(Time[0],Low[0] - 8 * Point,233,Blue); criteria = 0; } } } if TotalTrades < 1 and (h115min > 0 and StK15min > StD15min and StK15min < 70 and StK > StD and Ceil(StK) < 45) or (h115min == 1 and McClhist15min >= 0.0001 and StK15min < 75) then { SetOrder(OP_SELL,lotsi,Ask,slippage,x,0,Blue); SetArrow(Time[0],Low[0] - 1 * Point,233,Green); Trailing_point = Ask - TrailingStop * Point; if h115min == 1 and McClhist15min >= 0.0001 and StK15min < 75 then criteria = 2 else criteria = 1; if criteria == 1 then SetText(Time[0],Low[0] - 4 * Point,"1",Blue)else SetText(Time[0],Low[0] - 4 * Point,"2",Blue); if debug == 1 then { Print("!!!! Opening new sell: ","Criteria: ",criteria," ","day: ",Day," ","hr: ",Hour," ","mi: "," ",Minute," ","stk15min: "," ",StK15min," ","StD15min: ",StD15min," ","h115min: ",h115min); Print("!!!! Opening new sell: ","Stk: ",StK," ","StD: ",StD," ","PSar: ",iSAR(step,maximum,0)," ","High: ",High[0]," ","Low: ",Low[0]); } } if (criteria == 1 and ((StK < StD and Ceil(StK) > 60) or (StK15min < StD15min and StK15min > 60))) or (criteria == 2 and h115min == -1) then { for i = 1 to TotalTrades { if Ord(i,VAL_TYPE) == OP_SELL and OrderValue(i,VAL_SYMBOL) == Symbol then { if debug == 1 then { Print("!!!! Closing Open Sell: ","Criteria: ",criteria," ","day: ",Day," ","hr: ",Hour," ","mi: "," ",Minute," ","stk15min: "," ",StK15min," ","StD15min: ",StD15min," ","h115min: ",h115min); Print("!!!! Closing Open Sell: ","Stk: ",StK," ","StD: ",StD," ","PSar: ",iSAR(step,maximum,0)," ","High: ",High[0]," ","Low: ",Low[0]); } CloseOrder(Ord(i,VAL_TICKET),Ord(i,VAL_LOTS),Ask,slippage,White); SetArrow(Time[0],High[0] + 8 * Point,234,Red); criteria = 0; } } } if TotalTrades < 1 and (h115min == -1 and StK15min < StD15min and StK15min > 30 and StK < StD and Ceil(StK) > 60) or (h115min == -1 and McClhist15min <= -0.0001 and StK15min > 25) then { SetOrder(OP_BUY,lotsi,Bid,slippage,y,0,Red); SetArrow(Time[0],High[0] + 2 * Point,234,Purple); Trailing_point = Bid + TrailingStop * Point; if h115min == -1 and McClhist15min <= -0.0001 and StK15min > 25 then criteria = 2 else criteria = 1; if criteria == 1 then SetText(Time[0],High[0] + 4 * Point,"1",Blue) else SetText(Time[0],High[0] + 4 * Point,"2",Blue); if debug == 1 then { Print("!!!! Opening New Buy: ","Criteria: ",criteria," ","day: ",Day," ","hr: ",Hour," ","mi: "," ",Minute," ","stk15min: "," ",StK15min," ","StD15min: ",StD15min," ","h115min: ",h115min," ","McclHist: ",McClHist); Print("!!!! Opening New Buy: ","Stk: ",StK," ","StD: ",StD," ","PSar: ",iSAR(step,maximum,0)," ","High: ",High[0]," ","Low: ",Low[0]); } } Exit;