Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backbrush disappearing

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

    Backbrush disappearing

    Hello,

    I wrote a simple strategy that colors the background of a bar red, if the price of this bar crosses below the last SwingLow marker of the built-in indicator Swing, and green, if above. It works fine. Please see attached screenshot.

    I then added a logic that I found on the forum (e.g., here: https://forum.ninjatrader.com/forum/...nter-only-once) that should disable the coloring after the background has been brushed red or green for the first time. However, this seems to disable the entire strategy, as all the colored backgrounds disappear and not a single new one is brushed. Please see second screenshot.

    Please advise on why this is the case.

    Thank you very much in advance and best regards

    HHW

    #2
    Hello handelshandwerk,

    As you are not providing the code you want assistance with, it is hard to provide direction.

    In general you can use a bool to trigger an action once.

    private bool actionTriggered = false;

    In OnBarUpdate():

    if (actionTriggered == false && /* your conditions to trigger an action here */)
    {
    actionTriggered = true; // set the bool to true so the condition does not evaluate as true again
    BackBrush = Brushes.Red; // trigger the action here
    }


    To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition that triggers the action.
    The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.
    The debugging print output should clearly show what the condition is, what time the conditions are being compared, all values being compared, and how they are being compared.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    I am happy to assist you with analyzing the output from the output window.

    Run the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

    Below is a link to a support article that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.


    Let me know the date and time the behavior occurred or when you are expecting the behavior to occur.

    Please let me know if I may further assist with analyzing the output or if you need any assistance creating a print or enabling TraceOrders.​
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      Thank you for your reply.

      I am currently using only Strategy Builder and do not make any changes to the resulting code via NinjaScript. So, at the moment I shy away from inserting any kind of debugging code via NinjaScript myself.

      I tried to attach the .cs file from the strategy folder for your reference. I got the error message "Error uploading image". When I tried to copy/paste the code from Editor into this post, I got another error message. Please advise on how I can provide you with the code.

      Short recap: I have used a boolean as you suggested already. However, everything works fine only as long as I do not set the boolean to true after the first time a bar gets brushed (please see screenshots - that is basically all there is to the strategy. When I set the boolean to true, all brushes disappear.

      Thank you for your continued support to resolve this.

      Best,

      Christian
      ------------​

      Comment


        #4
        Hello handelshandwerk,

        May I confirm you have watched the video 'Debugging with the Strategy Builder' as directed?


        To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
        1. Click Tools -> Export -> NinjaScript Add-on...
        2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
        3. Click the 'Export' button
        4. Enter the script name in the value for 'File name:'
        5. Choose a save location -> click Save
        6. Click OK to clear the export location message
        By default your exported file will be in the following location:
        • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
        Below is a link to the help guide on Exporting NinjaScripts.
        http://ninjatrader.com/support/helpG...nt8/export.htm

        "Short recap: I have used a boolean as you suggested already. However, everything works fine only as long as I do not set the boolean to true after the first time a bar gets brushed (please see screenshots - that is basically all there is to the strategy. When I set the boolean to true, all brushes disappear."

        From my understanding of your post, you only want to change the color of 1 chart bar. When you say all the brushes dissapear this is not making sense to me as there should only be 1 chart bar with a changed color. Further, not changing the color of chart bars after the event would not undo the 1 chart bar that had the color changed.

        That said, the print output would provide the information I need to assist you with understanding the behavior of the strategy. Without this, I wouldn't be able to say if the condition is evaluating as true or false.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by TrippTraders, Yesterday, 07:14 PM
        1 response
        12 views
        0 likes
        Last Post brucerobinson  
        Started by decosenty, Yesterday, 11:33 PM
        0 responses
        9 views
        0 likes
        Last Post decosenty  
        Started by RicharBarrio, Yesterday, 11:26 PM
        0 responses
        7 views
        0 likes
        Last Post RicharBarrio  
        Started by paulo_br, 09-13-2024, 08:41 AM
        8 responses
        1,155 views
        0 likes
        Last Post AppleID25  
        Started by mno_om, Yesterday, 08:44 PM
        0 responses
        11 views
        0 likes
        Last Post mno_om
        by mno_om
         
        Working...
        X