1

I have never heard of ThinkOrSwrim till yesterday when someone asked me to convert a ThinkOrSwim script to an MQL4 indicator.

A part of the code is as follows:

input length = 21;
input price = close;
input ATRs=1;
input trueRangeAverageType = AverageType.WILDERS;
def flag;

def EMA = ExpAverage(close, length);

def shift1 = ATRs * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);

I want to ask you to kindly check and let me know if my understanding is correct.

input ATRs=1; // This should be a multiplier for ATR, then I think I should give it a double 
              //type for more flexible control.

input trueRangeAverageType = AverageType.WILDERS;
//As far as I understood, wilders is the same as SMMA in MQL.

.

 def shift1 = ATRs * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);

Here is the main piece of this code which I need your help with. My understanding is as follows

ATRs ==>> Just a multiplier

I think the rest of this line is calculating the ATR, right? If so, then I can see that I cannot simply convert this to iATR (in mql), because we are not able to choose MA Methode of ATR in mql4. Then I think first I have to put the "True Range" of each bar in an array and then use this array as a price source to get the averages.

MQL4:

for(int i = 0; i < rates_total; i++)
     {
      data[i] = iATR(_Symbol, TF_1, 1, i);
     }
for(int i = 0; i < limit; i++)
     {
      ExtBuffer[i] = iMAOnArray(data, 0, Inplenght, 0, InpMAMethod, i);
     }

If I'm in the right way yet, Then I think the iATR period has to be 1, to have the TrueRange of each bar and not the average of the TrueRanges. And then have the variable length (from thinkOrSwim inputs) as the period parameter for iMAOnArray.

I would appreciate any help with it.

Regards

Edit: I forgot to ask you something, why should the programmer who wrote this thinkscript code call this variable shift1?

  • You're in the right way, but the ATR timeframe has to be the same as intended, for the timeframe you work one. ATR is calculated based on high and low of the bars, also in your TOS code, then you make MA on the whole ATR data based on SMMA method. – Investing TS Nov 04 '21 at 08:30
  • The name *shift1* depends on what he does with it later on in the code. If he uses this value to determine TP/SL level or offset for entry, then the name is somewhat understandable. – Investing TS Nov 04 '21 at 08:31
  • Thank you Investing TS The project was done a long time ago, so I didn't check the treat for a while. That's why I reply late. Thank you again for your time and guides. – Reza Nasimi Dec 14 '21 at 09:02

0 Answers0