Menu
Brokers
MT4 Forex Brokers
MT5 Forex brokers
PayPal Brokers
Skrill Brokers
Oil Trading Brokers
Gold Trading Brokers
Web Browser Platform
Brokers with CFD Trading
ECN Brokers
Bitcoin FX Brokers
PAMM Forex Brokers
With Cent Accounts
With High Leverage
Cryptocurrency Brokers
Forums
All threads
New threads
New posts
Trending
Search forums
What's new
New threads
New posts
Latest activity
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Reply to thread
Forums
Trading Platforms
MetaTrader Expert Advisors
PSAR EA code problem
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
[QUOTE="ezraluandre, post: 201397, member: 67482"] Hi I had a simple EA code using Parabolic SAR indicator. In here I tried to determine the SAR direction base on SAR position. [CODE=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"); } //+------------------------------------------------------------------+[/CODE] 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 [ICODE]sar(1)>Bid[/ICODE] to [ICODE]sar(1)>Bid && sar()<Bid[/ICODE] it do nothing on strategy tester. Anyone can help me with this issue? [/QUOTE]
Insert quotes…
Verification
Post reply
Top
Bottom
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…