• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss Name - for multiple stop loss orders

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

  • priceisking
    started a topic SetStopLoss Name - for multiple stop loss orders

    SetStopLoss Name - for multiple stop loss orders

    In My strategy, i have code that places two different orders and i have stop loss orders for each. I later want to move the stops but trying to give a name to the order doesn't seem to work. How can i give it a name so that i can move the correct stop order ?


    if (firstEntry)
    {

    firstEntryOrder = EnterLong(Convert.ToInt32(DefaultQuantity), @"FirstLong");
    SetProfitTarget(CalculationMode.Ticks, ProfitTarget);
    SetStopLoss(firstEntryOrder.Name,CalculationMode.T icks, StopLoss);
    firstEntry = false;
    }

    else if (!firstEntry && BarsSinceExitExecution() > 4)
    {

    secondEntryOrder = EnterLong(Convert.ToInt32(DefaultQuantity), @"SecondLong");
    SetProfitTarget(CalculationMode.Ticks, ProfitTarget);
    SetStopLoss(secondEntryOrder.Name,CalculationMode. Ticks, StopLoss);

    }

    .
    .
    .
    .
    .
    .
    .

    if ((Close[0] - Position.AveragePrice) > 4
    SetStopLoss(secondEntryOrder.Name,CalculationMode. Price, Position.AveragePrice + 2 * TickSize);



    I keep getting a message:
    The name firstEntryOrder does not exist in the current context.
    The name secondEntryOrder does notexist in the current context.


    It seems like in document i can use fromEntrySignal
    https://ninjatrader.com/support/helpGuides/nt8/en-us/

    not sure if i used it correctly.

  • NinjaTrader_PaulH
    replied
    Hello priceisking,

    Thanks for your reply.

    You could use OnExecution() and check for the entry name and also the price.

    https://ninjatrader.com/support/help...tionupdate.htm

    https://ninjatrader.com/support/help...?execution.htm (Provides examples of checking by name)

    Leave a comment:


  • priceisking
    replied
    One more question. How can I determine the averageprice of both of the entries?

    for example if firstentry order is executed, then after 4 bars, the second entry is executed.

    Is there a way to calculate entryprice of each of the order? this way i don't have to use average price to set the appropriate stops.

    Let me know if this question makes sense.

    Thanks,

    Leave a comment:


  • priceisking
    replied
    thank you so much!

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    Hello priceisking,

    Thanks for your reply.

    Yes, you would want to use the same entry name for both stop and profit when you want them tied together.

    Leave a comment:


  • priceisking
    replied
    Thank you. Do i have to do the same thing for SetProfitTarget ? To create an OCO type order?

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    Hello priceisking,

    Thanks for your post.

    The signal names you would want to put in the SetStopLoss() methods are "FirstLong" and "SecondLong".

    Example: SetStopLoss("FirstLong",CalculationMode.Ticks, StopLoss, false);
    Last edited by NinjaTrader_PaulH; 04-02-2019, 08:45 AM. Reason: SetStopLoss() requires 4 parameters, the last is the bool for isSimulatedStop

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by indy73, Today, 10:52 PM
0 responses
3 views
0 likes
Last Post indy73
by indy73
 
Started by martyn73, Today, 07:04 PM
0 responses
5 views
0 likes
Last Post martyn73  
Started by sergey_z, Today, 02:56 PM
1 response
10 views
0 likes
Last Post NinjaTrader_Jesse  
Started by samir, Today, 02:46 PM
1 response
20 views
0 likes
Last Post NinjaTrader_Kate  
Started by neoikon, Today, 02:24 PM
1 response
8 views
0 likes
Last Post NinjaTrader_ChristopherJ  
Working...
X