Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculations in strategy builder.

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

    Calculations in strategy builder.

    Hello!
    I am developping a strategy now, but I am facing real problems to move forward.
    I am wondering if there is a way to make complex calculations in Strategy builder. I have developped an indicator and thought I could copy it to strategy builder, but I have realized that it is not working that way.

    I am failing to make such calculations:
    HTML Code:
    double val1 = Math.Min(Math.Max(double val2, - double val3), val4);
     double val5 = (Close[0] - Open[0])/3
    What I have done is that I have unlocked the script before I could make those calculations, but while testing the strategy in analyser, there was no accuracy.

    I also have the following code:
    HTML Code:
    if(Open[0] < Close[0])
    {
    if(Open[2] < Close[2]
    enterLong();
    }}
    In the strategy builder, I have code only the firt condition as well as "enterLong();
    here again, I unlocked the script and I continue in unlocked script.

    1) Could you please tell me if I can implement just one line of the conditions and continue with others in the unlocked script? How accurate would be this procedure?
    2) Can the calculations be done only in unlocked script?

    Any help would be welcome.

    Many thanks in advance.


    #2
    Hello Stanfillirenfro,

    To do more complex calculations you generally would use an indicator. What you already created can likely be used, you need to Plot the result of your calculation if the strategy is to use that value. You can use AddPlot in the indicator to create a plot and then you would need to assign a value. You can then access that indicator in the strategy builder to make conditions.

    An example would be:

    Code:
    double val1 = Math.Min(Math.Max(double val2, - double val3), val4);
    double val5 = (Close[0] - Open[0])/3
    Value[0] = val5;


    Comment


      #3
      Many thanks Jesse for that quick reply.
      I have used AddPlot in my indicator where I am currently using trianbleup/down and dots. The indicator is working very well on the chart with triangle and dots.
      My main problem would be to acces the indicator in Strategy builder. Could you please advise how to proceed? Is there a link to see/leran how it works?
      Also, how accurate could be the result if I write only one condition in strategy builder when I have more for the same event and unlock the script to continue?

      Thanks in advance!

      Comment


        #4
        Hello Stanfillirenfro,

        If you created an indicator you should now be able to select it when making conditions. That would be under the Indicators folder in the condition builder. This would appear just like the system indicators and would be the name you used for the indicator.

        I couldn't comment on accuracy, the strategy builder would execute the same calculation as the indicator normally does so it would depend on what you programmed. You would have to check the results when you use it to make sure it works as you had expected. Generally using Prints to output the indicators values from the strategy is the way to do that.



        Comment


          #5
          Many thanks for your reply!
          I have an issue here. since there are conditions some for log and some for short, by selecting the indicator, how to chose these conditions for each direction in the same indictor?

          Comment


            #6
            Hello Stanfillirenfro,

            I am not sure I understand, are you saying that in the indicator you made some user inputs to control long/short?

            If that was the question then you should see any user input properties when you configure the indicator in the builder.

            Comment


              #7
              Yes Jesse, in the indicator, I have some inputs controling long/short.

              I will revert to you after trying.

              Thanks for your help and see you very soon.

              Comment


                #8
                Hello Jesse!
                I revert to you now because I am facing some problems again.

                I have the indicator coded as followed for example:

                HTML Code:
                if(Open[0] < Close[0])
                {
                  if(Open[1] < Close[2])
                  {
                   if(Open[1] > Close[3])
                 {
                    Buys[0] = Low[0] - 2*TickSize;
                  }
                 }
                }
                Now I have this code in the indicator. In Strategy builder, in "Conditions and actions", when I hit the "add" button of the signal conditions, it is confusing what I have to select on the left side. Should the selction be made in "Price" like for example "Close, Open, High"? On the right side, I went under "indicators" and I could select "Buys". But the problem here is to know how the comparison (greater, less...is to be, since I have these conditions already in the indicator.

                How to proceed here please?

                Thanks ind advance.

                Comment


                  #9
                  Hello Stanfillirenfro,

                  but the problem here is to know how the comparison (greater, less...is to be, since I have these conditions already in the indicator.
                  That depends on what you want to do with that price value. If you wanted to compare that some other series crossed or is more/less then what you have is essentially ok for that but you would need to carry over the value.

                  The condition would look like:
                  Left: Price -> Close
                  Center: CrossAbove
                  Right: Indicators -> MyIndicatorName -> Buys

                  That also assumes a constant value is set, so you would need:

                  Code:
                  if(CurrentBar < 1) return;
                  Buys[0] = Buys[1];
                  if(Open[0] < Close[0])
                  {
                     if(Open[1] < Close[2])
                     {
                        if(Open[1] > Close[3])
                        {
                           Buys[0] = Low[0] - 2*TickSize;
                        }
                      }
                  }
                  Now if the condition was already done in the indicator meaning that if Buys was set that means a signal then you need to change how the indicator sets a value. I would suggest adding a Third plot and naming it SignalPlot.
                  Your code would then look like the following:
                  Code:
                  SignalPlot[0] = 0; // reset the plot on each new bar
                  if(Open[0] < Close[0])
                  {
                     if(Open[1] < Close[2])
                     {
                        if(Open[1] > Close[3])
                        {
                           Buys[0] = Low[0] - 2*TickSize;
                            SignalPlot[0] = 1; 
                        }
                      }
                  }
                  That would make the condition in the builder:

                  Left: Indicators -> MyIndicatorName -> SignalPlot
                  Center: Equals
                  Right: Misc -> Numeric Value -> 1

                  That would be true for a single bar whenever that condition in the indicator is true.

                  Comment


                    #10
                    Many thanks Jesse for your help.

                    It is becoming clearer. I am improving the strategy from now and I will revert to you for feedback.

                    Many thanks again!

                    Comment


                      #11
                      Hello Jesse!

                      All the above issues have been resolved thanks you. For that many thanks again.

                      Let's us please move forward. While testing my strategy with analyser, I have realized that when two trades are near each other, that mean when the second trade occurs within the size of the take profit of the first trade, there is no trigger for the second trade. How can I fix this problem so that I can catch all trades in the same direction even if the previous trades are still running?

                      I think the problem should be between "Entries per direction" and "Entry handling" of "More properties" under "Default properties". What should I understand here and how should I handle this part in order to catch all trades in the same direction?

                      Many thanks in davance.

                      Comment


                        #12
                        Hello Stanfillirenfro,

                        You mentioned there is no trigger for the second trade, did you mean that the condition is not becoming true?

                        The entries per direction controls how many entries can be submitted at once in the same direction, that would need to be set to 2 if your conditions are happening within the same bar.



                        Comment


                          #13
                          Hello Jesse and many thanks for your reply.

                          You mentioned there is no trigger for the second trade, did you mean that the condition is not becoming true?
                          Of courses the condition is true but because the first trade is still running, there could not be any trigger for the second trade. The second trade should be occuring NOT on the same bar as the first one, but after the bar for the first trade was mature.

                          Comment


                            #14
                            Hello Stanfillirenfro,

                            To clarify, you want to submit the first entry and then wait 1 bar until the first entry was filled?

                            Comment


                              #15
                              Hello Jesse!

                              To clarify, you want to submit the first entry and then wait 1 bar until the first entry was filled?
                              No I have to wait until
                              1) The profit traget is hit or
                              2) The stop loss is hit.

                              So the second trade can take place only if the first trade is complete. That means, it is not possible to have two trades running in the same direction.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Today, 05:17 AM
                              0 responses
                              44 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              124 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              65 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              42 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              46 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X