Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calling an Indicator in Strategy

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

    Calling an Indicator in Strategy

    Hi,

    I've a question on how to call an indicator in a strategy. For example, if I wanted to call buy when Parabolic SAR was below the price in a buy trend and call sell when Parabolic SAR was above the price in a sell trend. What's the if statement for this?

    Thanks!

    #2
    Hello, thanks for writing in. The support team will not be able to write out specific code. But I will show you how to access and print out the data you can get from the Parabolic SAR indicator, then you can take this code and implement it into a trading strategy and test the output.

    For examples on accessing indicator data for the Parabolic SAR first see the help guide examples:


    Code:
    double SARvalue = ParabolicSAR(0.02, 0.2, 0.02)[0];
    Print("The current ParabolicSAR value is " + value.ToString());​
    The part here: ParabolicSAR(0.02, 0.2, 0.02)[0] is referencing the latest value of the parabolic SAR. Taking this further, you can start to find your trading strategy by comparing this to the Close[0] value, which is the latest price of the security on the same bar:

    Code:
    Print("SARvalue " + SARvalue);
    Print("Close[0] " + Close[0]);
    Then go further by incorporating these two values into an IF statement, and print when this is true.

    Code:
    if(SARvalue > Close[0])
    {
    Print("The SAR is above the Close price " + Time[0]);
    }
    
    if(SARvalue > Close[0])
    {
    Print("The SAR is below the Close price " + Time[0]);
    }
    From this kind of testing is how you will start to get comfortable accessing and creating conditions for your custom strategies. ​

    Comment


      #3
      Thanks Chris for your reply.

      So if I added the indicator in State.Dataloaded, then would an example be:

      if (Close[0] > ParabolicSAR[0])
      EnterLong;

      Comment


        #4
        Hi, thanks for the follow up. This code will need to go into the OnBarUpdate method. It will likely take much more code than just

        if (Close[0] > ParabolicSAR[0])
        EnterLong();​

        to get the strategy you are aiming to build, so this is why I suggest printing out every piece of data you are using in your script. I was able to provide some test code in my first reply as a courtesy, but I will unfortunately not be able to help develop an entire strategy.

        Comment


          #5
          Thanks Chris. The example that you provided will go into OnBarUpdate as well, correct?

          Comment


            #6
            That is correct.

            Comment


              #7
              Sorry one more question. If I wanted the indicator on the third data series. How would I do that?

              Comment


                #8
                Hi, you can pass in the BarsArray object like so:

                double SARvalue = ParabolicSAR(BarsArray[2], 0.02, 0.2, 0.02)[0];

                Comment


                  #9
                  Thank you!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Yesterday, 05:17 AM
                  0 responses
                  58 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  133 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  73 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  45 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  50 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X