dignitas123:
The issue may be trivial: I want to set a custom start for the standard Parabolic SAR Indicator calculation. So I need to be able to input two variables.
Fore example: input double CandlesBack = 10; input bool Direction = true; --> The SAR dots calculation should now start on the lowest candle within the last 10 candles.
WHRoeder:
That is not how SAR works, so what you ask is not trivial. What you want will be almost a complete rewrite. All the SaveReverse and dir_long will be gone and two sets of variables (one for each direction) will be required.
Thank you for answering WHRoeder.
As it was too complicated for me to rewrite the Indicator I have written an EA that does the job for me :)
I wanted to use the SAR not for spotting Trends but instead for trailing my stop out of a Trend Correction.
Here is the code when someone needs it ^^
//+------------------------------------------------------------------+ //| ParabolicExpert| //| by dignitas| //| niclashumm@aol.com| //+------------------------------------------------------------------+ //--- input parameters input double InpSARStep=0.02; // Step input double InpSARMaximum=0.2; // Maximum extern int BarsBack = 8; // length (bars) extern int Direction = 0; // 0 = long; 1 = short extern color Color = Black; // Channel color //--- global parameters int bars, initialbars;double lastSar, pivot, acc = InpSARStep; //--------------------------------------------------------------- 1 -- void OnInit() { if(Direction==0){ bars = iLowest(NULL,0,MODE_LOW,BarsBack,1); } else { bars = iHighest(NULL,0,MODE_HIGH,BarsBack,1); } Create(); return; initialbars = Bars; } //--------------------------------------------------------------- 2 -- void OnTick() { if(Bars!=initialbars){ initialbars = Bars; bars++; Create(); } } //--------------------------------------------------------------- 5 -- void OnDeinit(const int reason) { for(int i = bars;i > 0;i--) { ObjectDelete("Dot"+i); } acc = InpSARStep; } //--------------------------------------------------------------- 6 -- void Create() { for(int i = bars;i > 0;i--) { datetime time = Time[i]; string objName = "Dot"+i; double preis = function(i); ObjectCreate(objName,OBJ_TEXT,0,time,preis+100*Point); ObjectSetText(objName, CharToStr(159), 14, "Wingdings", White); WindowRedraw(); } } double function(int i) { double sar; // LONG if(Direction == 0) { if(i==bars) { sar = Low[i]; lastSar = sar; pivot = High[i]; } else { sar = lastSar + acc * (High[i+1] - lastSar); lastSar = sar; if(acc < InpSARMaximum) { if(High[i]>pivot){ acc+=InpSARStep; pivot = High[iHighest(NULL,0,MODE_HIGH,bars-i,i)]; } } } // SHORT } else { if(i==bars) { sar = High[i]; lastSar = sar; pivot = Low[i]; } else { sar = lastSar + acc * (Low[i+1] - lastSar); lastSar = sar; if(acc < InpSARMaximum) { if(Low[i]<pivot){ acc+=InpSARStep; pivot = Low[iLowest(NULL,0,MODE_LOW,bars-i,i)]; } } } } return(sar); }
dignitas123: I wanted to use the SAR not for spotting Trends but instead for trailing my stop out of a Trend Correction
| For that all you need to do is verify that iSar was on the correct side of price and use the value.
double sar = iSar(...); if(sar < Bid && OrderType() == OP_BUY) MoveSL( OrderTicket(), sar); |

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello mql4 Community,
Recently I stumbled accross a problem which I can't seem to solve by my own, neither have I found any solution in this forum and I'm really not an expert in setting up indicators in mql4...
The issue may be trivial: I want to set a custom start for the standard Parabolic SAR Indicator calculation. So I need to be able to input two variables.
Fore example: input double CandlesBack = 10; input bool Direction = true; --> The SAR dots calculation should now start on the lowest candle within the last 10 candles.
If you can help me with the issue or give me a gross direction where I should start changing the code I would be very thankful.
Cheers
Here is the code: