Jump to content
Medved Trader Forums

Paintbar indicator values when backtesting


Recommended Posts

Hey,

If the Paintbar code include values such as the Moving Average, will the indicators value be considered at the time of the data or whatever they are now.
For example: It is Jan 04, 2021 and the SMA value is 100. Today Jan 21, 2021; looking at the SMA value on Jan04 it would show for example 105.

So will the SMA value in the Paintbar on Jan04,2021 use 100 or 105? 

Thanks

Link to comment
Share on other sites

I think you are talking about frequency, not timeframe and really don't understand what "gone" means in your example. When initially computing the timeframe, MT calls your code for the timeframe once for every candle on the chart. Then as new quotes come in, it will call it again just for the updated candles. If you change frequency on the chart, the chart will need to be recomputed, so the entire process is done again. 

Link to comment
Share on other sites

if (Last > Prev_Low && Last < Prev_High && Last > EMA20)
{
SetScanResult(@"bullish");
SetColor("blue", Color.Blue);
}

 

 

Last,Prev_High,Prev_Low are Variables based on Horizontal Line indicator. Apply it to TSLA on the 120min Frequency

Edited by 3acor
Link to comment
Share on other sites

So what is Last in Horizontal Line, same as SymbolData.Last?

I could use High and Low instead but I would like to use the High/Low for the current timestamp  such as in the post below. But I am not sure how to do it if I want to apply it for multiple trading sessions for backtesting.

 

Link to comment
Share on other sites

The Last, High, Low, Close come from the "Chart" - that is, current chart. Not from current-chart-up-to-the-candle-being-processed...

Prev Close, Prev Open etc. also come from the chart but they obviously don't change as new data gets added.

If you wanted to use High/Low for current timestamp, you'd keep track of it yourself. It is easy enough, you just have to define the DayHigh/DayLow and DayNum outside the function, zero it out when the DayNum is not equal to TradingDay.DayNumber, adjust the DayHigh and DayLow to the new candle's high and low, and set the DayNum to TradingDay.DayNumber.

 

double DayHigh = 0;
double DayLow  = 0;
int DayNum     = -1;

public void MainCalculation()
{
   if (DayNum != TradingDay.DayNumber)
   {
      DayNum  = TradingDay.DayNumber;
      DayHigh = High; DayLow = Low;
   }
   DayHigh = Math.Max(DayHigh, High);
   DayLow  = Math.Max(DayLow, Low);
}

If you want to restrict it to only regular session, you'd have to also condition it on other TradingDay. properties. Like TradingDay.IsPreMarket or something.

  • Thanks 1
Link to comment
Share on other sites

I am not sure why it is not working. This is my code applied to NNDM on Jan25 on the 120min frequency at 7am premarket

//PM_Low variable is Horizontal Line, Low, including premarket
//Prev_High variable is Horizontal Line, PrevHigh, Reg. sessions only

double PM_Low_now = 0;
int DayNum        = -1;

public void MainCalculation()
{

if (DayNum != TradingDay.DayNumber)
    {
        DayNum     = TradingDay.DayNumber;
        PM_Low_now = PM_Low;
    }
    else
    {
        PM_Low_now = Math.Min(PM_Low_now, PM_Low);
    } 

if (PM_Low_now > 0.98 * Prev_High)

  {
       SetColor("green", Color.Green);
  }

 

}

        

Edited by 3acor
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...