Hi I had a simple EA code using Parabolic SAR indicator. In here I tried to determine the SAR direction base on SAR position.
This code works as intended with small problem,
First, the code would be lagged by 1 bar, if SAR position change from above to below bid price the alert result still show SELL. ]
Second, when I tried to add condition from
Anyone can help me with this issue?
MQL4:
//+------------------------------------------------------------------+ //| Test.mq4 | //| Copyright 2021, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2021, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict double sar(int shift=0) { return iSAR(Symbol(),PERIOD_CURRENT,0.02,0.2,shift); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int OnInit() { //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { bool BUYCondition = sar()<Bid; bool SELLCondition = sar()>Bid; static datetime preTime=0,curTime; bool newBar=false; curTime=Time[0]; if(preTime!=curTime) { preTime=curTime; newBar=true; } if(Period() == PERIOD_MN1) newBar = false; //Minute 1 using tick //datetime some_time=D'2021.11.02 08:30'; //int shift=iBarShift(Symbol(),PERIOD_CURRENT,some_time); if(newBar && BUYCondition) Alert("BUY true"); if(newBar && SELLCondition) Alert("SELL true"); } //+------------------------------------------------------------------+
This code works as intended with small problem,
First, the code would be lagged by 1 bar, if SAR position change from above to below bid price the alert result still show SELL. ]
Second, when I tried to add condition from
sar(1)>Bid
to sar(1)>Bid && sar()<Bid
it do nothing on strategy tester.Anyone can help me with this issue?
Last edited by a moderator: