Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Strategy builder - breakeven after certain ticks/price

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

  • Emma1
    replied
    rafael_delima86 , you were reffering to prevoius example, i taught you had a clip of the questioned code.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello rafael_delima86,

    The general idea is to save the current price with an offset of the number of ticks of where you want the breakeven to be and then have a condition that compares the current price to that variable.

    Once the breakeven price is reached, the stop can be set to a new price.

    Please let me know if you have any questions about this, I am happy to assist.

    Leave a comment:


  • hedgeplay
    replied
    Originally posted by rafael_delima86 View Post

    Since I'm new to the whole coding thing, I find Paul's answer very hard to follow,,, my apologies

    "my apologies"

    Don't do that. This is what the support forum is for, to help you as you work to figure things out.



    "Since I'm new to the whole coding thing, I find Paul's answer very hard to follow.."


    The short answer is that you incorporate code from the example Paul referenced, the example Chelsea wrote.


    Incorporate steps 1-5 in the code snip below below into your OnBarUpdate() code right after your current Step 4. So the steps below should become steps 5-9 in your code.


    If if is not clear how to do that just ask the NT support team staff are very helpful as people work to figure out how to use Builder. Just tell them how far you have gotten and ask questions to help you get past the next step. They welcome your questions and are very good at responding.

    HedgePlay



    Code:
    // Set 1
    if ((TriggerState >= 2)
    && (Position.MarketPosition == MarketPosition.Flat))
    {
    TriggerState = 0;
    }
    
    // Set 2
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    TriggerState = 1;
    EnterLong(Convert.ToInt32(DefaultQuantity), @"entry");
    }
    
    // Set 3
    if ((TriggerState == 1)
    && (Position.MarketPosition == MarketPosition.Long))
    {
    TriggerState = 2;
    StopPrice = (Position.AveragePrice + (InitialStopDistance * TickSize)) ;
    TriggerPrice = (Position.AveragePrice + (BreakEvenTrigger * TickSize)) ;
    }
    
    // Set 4
    if ((TriggerState == 2)
    && (Close[0] >= TriggerPrice))
    {
    TriggerState = 3;
    StopPrice = Position.AveragePrice;
    Draw.Diamond(this, @"BreakEvenBuilderExample Diamond_1", true, 0, (High[0] + (2 * TickSize)) , Brushes.DarkCyan);
    }
    
    // Set 5
    if (TriggerState >= 2)
    {
    ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), StopPrice, @"exit", @"entry");
    }

    Leave a comment:


  • rafael_delima86
    replied
    Originally posted by hedgeplay View Post
    My empower people by teaching people how to fish for themselves answer ..
    Here is an example Google query that you can use to quickly find good info on many NinjaTrader topics.
    https://www.google.com/search?q=Ninj...+Even&ei=OHgDY


    A more direct answer from Paul in the good link he just posted here.
    https://ninjatrader.com/support/foru...-1#post1165795

    HedgePlay
    Since I'm new to the whole coding thing, I find Paul's answer very hard to follow,,, my apologies

    Leave a comment:


  • rafael_delima86
    replied
    Sorry Emma, I don't know if this is what you meant but I appreciate your help!!!

    Leave a comment:


  • hedgeplay
    replied
    Update: We were posting at the same time. Looks like you already found it!

    My empower people by teaching people how to fish for themselves answer ..
    Here is an example Google query that you can use to quickly find good info on many NinjaTrader topics.
    https://www.google.com/search?q=Ninj...+Even&ei=OHgDY


    A more direct answer from Paul in the good link he just posted here.
    https://ninjatrader.com/support/foru...-1#post1165795

    HedgePlay

    Leave a comment:


  • rafael_delima86
    replied


    #region Using declarations

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.ComponentModel.DataAnnotations;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

    using System.Windows;

    using System.Windows.Input;

    using System.Windows.Media;

    using System.Xml.Serialization;

    using NinjaTrader.Cbi;

    using NinjaTrader.Gui;

    using NinjaTrader.Gui.Chart;

    using NinjaTrader.Gui.SuperDom;

    using NinjaTrader.Gui.Tools;

    using NinjaTrader.Data;

    using NinjaTrader.NinjaScript;

    using NinjaTrader.Core.FloatingPoint;

    using NinjaTrader.NinjaScript.Indicators;

    using NinjaTrader.NinjaScript.DrawingTools;

    #endregion




    //This namespace holds Strategies in this folder and is required. Do not change it.

    namespace NinjaTrader.NinjaScript.Strategies

    {

    public class BLUEMOON : Strategy

    {

    private MACD MACD1;

    private MACD MACD2;

    private EMA EMA1;




    protected override void OnStateChange()

    {

    if (State == State.SetDefaults)

    {

    Description = @"";

    Name = "BLUEMOON";

    Calculate = Calculate.OnBarClose;

    EntriesPerDirection = 1;

    EntryHandling = EntryHandling.AllEntries;

    IsExitOnSessionCloseStrategy = true;

    ExitOnSessionCloseSeconds = 30;

    IsFillLimitOnTouch = false;

    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;

    OrderFillResolution = OrderFillResolution.Standard;

    Slippage = 0;

    StartBehavior = StartBehavior.WaitUntilFlat;

    TimeInForce = TimeInForce.Gtc;

    TraceOrders = false;

    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;

    StopTargetHandling = StopTargetHandling.ByStrategyPosition;

    BarsRequiredToTrade = 20;

    // Disable this property for performance gains in Strategy Analyzer optimizations

    // See the Help Guide for additional information

    IsInstantiatedOnEachOptimizationIteration = true;

    START = DateTime.Parse("08:00", System.Globalization.CultureInfo.InvariantCulture) ;

    END = DateTime.Parse("11:00", System.Globalization.CultureInfo.InvariantCulture) ;

    }

    else if (State == State.Configure)

    {

    }

    else if (State == State.DataLoaded)

    {

    MACD1 = MACD(Close, 10, 25, 9);

    MACD2 = MACD(Close, 10, 25, 9);

    EMA1 = EMA(Close, 8);

    MACD1.Plots[0].Brush = Brushes.DarkCyan;

    MACD1.Plots[1].Brush = Brushes.Crimson;

    MACD1.Plots[2].Brush = Brushes.Transparent;

    EMA1.Plots[0].Brush = Brushes.Goldenrod;

    AddChartIndicator(MACD1);

    AddChartIndicator(EMA1);

    SetStopLoss(CalculationMode.Ticks, 40);

    SetProfitTarget("", CalculationMode.Ticks, 60);

    }

    }




    protected override void OnBarUpdate()

    {

    if (BarsInProgress != 0)

    return;




    if (CurrentBars[0] < 1)

    return;




    // Set 1

    if ((Times[0][0].TimeOfDay >= START.TimeOfDay)

    && (Times[0][0].TimeOfDay <= END.TimeOfDay)

    && (CrossBelow(MACD1.Avg, MACD2.Avg, 1))

    && (Close[0] > EMA1[0]))

    {

    EnterLong(Convert.ToInt32(DefaultQuantity), "");

    }



    // Set 2

    if ((Times[0][0].TimeOfDay >= START.TimeOfDay)

    && (Times[0][0].TimeOfDay <= END.TimeOfDay)

    && (CrossBelow(MACD1.Avg, MACD2.Avg, 1))

    && (Close[0] < EMA1[0]))

    {

    EnterShort(Convert.ToInt32(DefaultQuantity), "");

    }



    // Set 3

    if (CrossBelow(MACD1.Avg, MACD2.Avg, 1))

    {

    ExitLong(Convert.ToInt32(DefaultQuantity), "", "");

    }



    // Set 4

    if (CrossAbove(MACD1.Avg, MACD2.Avg, 1))

    {

    ExitShort(Convert.ToInt32(DefaultQuantity), "", "");

    }



    }




    #region Properties

    [NinjaScriptProperty]

    [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]

    [Display(Name="START", Order=1, GroupName="Parameters")]

    public DateTime START

    { get; set; }




    [NinjaScriptProperty]

    [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]

    [Display(Name="END", Order=2, GroupName="Parameters")]

    public DateTime END

    { get; set; }

    #endregion




    }

    }

    Leave a comment:


  • Emma1
    replied
    I can modifying the tick/price strategy ,'My strategy is 99% ready but I'm stuck with the breakeven part'. have you the code.
    Last edited by Emma1; 08-01-2021, 10:04 AM.

    Leave a comment:


  • Strategy builder - breakeven after certain ticks/price

    Hello,
    I have looked all over a previous thread for help on BREAKEVEN after certain ticks/price. I found a zip file with a sample strategy but unfortunately when I try to copy the parameters from that strategy into mine, somehow my enter positions won't fill nor profit or stop loss. if anyone ever made it through this, PLEASE help a brother out!... My strategy is 99% ready but I'm stuck with the breakeven part...

Latest Posts

Collapse

Topics Statistics Last Post
Started by ezrollin, Today, 10:40 AM
1 response
3 views
0 likes
Last Post NinjaTrader_Jesse  
Started by sidlercom80, Today, 10:20 AM
1 response
4 views
0 likes
Last Post NinjaTrader_ChrisL  
Started by TraderElegante, Today, 09:53 AM
2 responses
16 views
0 likes
Last Post TraderElegante  
Started by Kreyenhagen, Today, 09:03 AM
1 response
7 views
0 likes
Last Post NinjaTrader_ChrisL  
Started by trader3000a, Today, 04:23 AM
1 response
10 views
0 likes
Last Post NinjaTrader_Jesse  
Working...
X