• 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

Help me with a order

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

  • NinjaTrader_Bertrand
    replied
    firecan, we can for sure understand the frustrations involved in custom coding and debugging, however unfortunately we would not offer such services - if you want this code rather professionally custom developed for you the best option would be checking with a certified NinjaScript consultant -

    http://www.ninjatrader.com/webnew/pa...injaScript.htm

    Leave a comment:


  • firecan
    replied
    Sorry, I am tired of trying to run the script, I take two months and nothing. If possible, please make it work will be grateful.

    Leave a comment:


  • NinjaTrader_RyanM1
    replied
    firecan,

    Make sure you are managing your bool variables effectively. They should be true initially and also reset back to true once you're flat.

    To help debug this: You can add print statements to any block of code to check if it's being processed properly.

    Simplify to a two stage movement first and verify this is working properly, before adding more movements.

    Leave a comment:


  • firecan
    replied


    {
    if (Close[0] >= Position.AvgPrice +3 * TickSize && PriMove)
    { SetStopLoss(CalculationMode.Price,Position.AvgPric e -
    5 * TickSize); PriMove = false; }

    if (Close[0] >= Position.AvgPrice +8 * TickSize && SegMove)
    { SetStopLoss(CalculationMode.Price,Position.AvgPric e +
    1 * TickSize); SegMove = false; }

    if (Close[0] >= Position.AvgPrice +14 * TickSize && TerMove)
    { SetStopLoss(CalculationMode.Price,Position.AvgPric e +
    7 * TickSize); TerMove = false; }

    if (Close[0] >= Position.AvgPrice +20 * TickSize)
    { SetStopLoss(CalculationMode.Price,Position.AvgPric e +
    15 * TickSize);}
    }

    // Condicion de Entrada en Largo.
    if (ToTime(Time[0]) == ToTime(horas,minutos,00))
    { EnterLongStop(
    0,true,contratos,Close[0] +7 * TickSize, "Largo 1"); }

    Leave a comment:


  • firecan
    replied
    protectedoverridevoid Initialize()

    {
    SetStopLoss(CalculationMode.Ticks, stoplossticks);
    SetProfitTarget(CalculationMode.Ticks, profittargetticks);

    TraceOrders =
    true ;
    CalculateOnBarClose =
    true;
    }

    protectedoverridevoid OnBarUpdate()
    {
    // Resetea stop loss y profit al cerrar la posicion.
    if (Position.MarketPosition == MarketPosition.Flat)
    { SetStopLoss(CalculationMode.Ticks, stoplossticks); }

    // Abierta una posicion Larga, modifica el Stop Loss a Breakeven.
    if (Position.MarketPosition == MarketPosition.Long)


    Leave a comment:


  • firecan
    replied
    Hello.

    I re-wrote the scrip without variables to make it look more clear about what I do.

    Could you make it run and tell me where is the error it does not work.

    I try to place a pending order on the market at a particular time. And run the stop loss 3 times when touch each price set, without wait close a bar.

    I do not why the stop loss only run when the price is +20 , and forget +3 , +8 an +14 ticks.

    Regards

    Leave a comment:


  • NinjaTrader_RyanM1
    replied
    firecan,

    You want to reset the stop loss to an initial value when flat. You also want to reset your bool flag.

    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetStopLoss(CalculationMode.Ticks, 20);
    PriMove = true;
    }

    Leave a comment:


  • firecan
    replied
    Hello again, sorry.

    I'm confused . Please, could you write me the missing piece of code and tell me where I put it, thanks

    Regards.

    Leave a comment:


  • NinjaTrader_Brett
    replied
    Hello,

    These are variable declarations when the script is loaded.

    You need to reset this Inside of as well when it is needed to be reset.

    OnBarUpdate()
    {


    }

    Let me know if I can be of further assistance.

    Leave a comment:


  • firecan
    replied
    I have :

    #region Variables

    private int contratos = 1;
    private int profittargetticks = 50;
    private int stoplossticks = 10;
    private int distmercado = 7;
    private int distbreak1 = 0;
    private int enviabreak1 = 0;
    private int distbreak2 = 0;
    private int enviabreak2 = 0;
    private int horas = 0;
    private int minutos = 0;
    private bool PriMove = true;
    #endregion

    Leave a comment:


  • NinjaTrader_JoshP
    replied
    firecan,

    Your code uses PriMove, but you never reset its value anywhere. You will most likely need logic to reset it or else it will only act once and then never again.

    Leave a comment:


  • firecan
    replied
    Hello again.

    This is the code, can you tell me if is it ok.

    protectedoverridevoid Initialize()

    {
    SetStopLoss(CalculationMode.Ticks, stoplossticks);
    SetProfitTarget(CalculationMode.Ticks, profittargetticks);

    TraceOrders =
    true ;
    CalculateOnBarClose =
    true;
    }

    protectedoverridevoid OnBarUpdate()

    {
    // Resetea stop loss y profit al cerrar la posicion.
    if (Position.MarketPosition == MarketPosition.Flat)
    { SetStopLoss(CalculationMode.Ticks, stoplossticks); }

    // Abierta una posicion Larga, modifica el Stop Loss a Breakeven.
    elseif (Position.MarketPosition == MarketPosition.Long)

    {
    /* Cuando el precio es mayor que la entrada en + ? ticks
    envia el Stop Loss a Breakeven +/- ? */

    if (Close[0] >= Position.AvgPrice + distbreak1 * TickSize && PriMove)
    { SetStopLoss(CalculationMode.Price,Position.AvgPric e - enviabreak1 * TickSize); PriMove =
    false; }

    if (Close[0] >= Position.AvgPrice + distbreak2 * TickSize)
    { SetStopLoss(CalculationMode.Price,Position.AvgPric e + enviabreak2 * TickSize); }
    }

    // Condicion de Entrada en Largo.
    if (ToTime(Time[0]) == ToTime(horas,minutos,00))
    { EnterLongStop(
    0, true, contratos, Close[0] + distmercado * TickSize, "Largo 1"); }

    Leave a comment:


  • NinjaTrader_Austin
    replied
    Originally posted by firecan View Post
    Hello.

    Dont run OK, something I'm doing wrong.

    Maybe dont understand "Reset these variables when you're flat."

    How can I do it.

    Regards.
    Firecan, what Ryan means is that when your strategy is flat, reset the stop losses to a price of 0.
    Code:
    if (Position.MarketPosition == MarketPosition.Flat)
    {
       SetStopLoss(CalculationMode.Price, 0);
    }

    Leave a comment:


  • firecan
    replied
    Hello.

    Dont run OK, something I'm doing wrong.

    Maybe dont understand "Reset these variables when you're flat."

    How can I do it.

    Regards.

    Leave a comment:


  • NinjaTrader_RyanM1
    replied
    What's happening is your first condition continues to evaluate true. What you can do here is use bool variables so that this first movement is only evaluated once.

    VariablesRegion:
    private bool firstMove = true;


    Code:
     
    if (Close[0] >= Position.AvgPrice + 8 * TickSize && firstMove)
    {
     SetStopLoss(CalculationMode.Price,Position.AvgPrice + 1 * TickSize);
    firstMove = false;
    }
     
     
    if (Close[0] >= Position.AvgPrice + 14 * TickSize)
    {
    SetStopLoss(CalculationMode.Price,Position.AvgPrice + 7 * TickSize);
    }
    Reset these variables when you're flat.
    Last edited by NinjaTrader_RyanM1; 10-22-2010, 03:54 PM.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by darkgreen, Today, 09:36 AM
1 response
4 views
0 likes
Last Post NinjaTrader_Kate  
Started by JuanPabloQuevedo, Today, 01:04 PM
1 response
6 views
0 likes
Last Post NinjaTrader_Tyler  
Started by augustfay, Today, 10:46 AM
1 response
18 views
0 likes
Last Post NinjaTrader_Kate  
Started by neilzep, Today, 11:16 AM
3 responses
19 views
0 likes
Last Post NinjaTrader_PaulH  
Started by thebanik, Today, 10:18 AM
1 response
11 views
0 likes
Last Post NinjaTrader_ChristopherS  
Working...
X