Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Average Price

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Average Price

    Hallo.
    I would like to calculate everage High - Low price of for example 2 former bars and save this price in variables.
    Waht is the syntax to calculate average price?
    Sample: ((High[1]-Low[2])+(High[2]-Low[2]))/2
    I know I should create double variable "average"
    if something..
    {
    average = ?????
    }
    What should be on right side??
    Rgds
    Czarek

    #2
    An easier approach would be:

    double myVariable;
    myVariable = SMA(Range(), 2)[1];
    RayNinjaTrader Customer Service

    Comment


      #3
      Hallo Josh.

      I would like to save to myVariable = SMA(Range(), 2)[1]; only one time a week Friday in the market closin of 16:00 or Monday at 16:15 in the market open time (this is for forex). What condition shoul I use to save it and keep unchanged all week??
      Rgds
      Czarek.

      Comment


        #4
        Hello,

        Use DayOfWeek and a time condition with a bool flag:



        if (Time[0].DayOfWeek == DayOfWeek.Friday
        && ToTime(Time[0]) >= 160000
        && !myVariable_is_set)
        {
        myVariable = SMA(Range(), 2)[1];
        myVariable_is_set = true;
        }

        This link and sample will help:


        At some point you will need to set myVariable_is_set to false so the condition will evaluate to true.
        DenNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        563 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        329 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        548 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X