PDA

View Full Version : Instant Exits and Bars updates


Agamenon
11-08-2007, 06:58 AM
Hi! I trying to make instant exits with indicator crossovers! But always exits in next bar update. Itīs possible to get exit at moment? here my sample:


// Conditional on OnBarUpdate()
if (( CrossAbove(KPA900(), KPAutoStop(), 1)) && TipoTrade == "Venta")
{
// Debug Flag
Print (" KPA900 Cruza sobre KPAutoStop en Variable de Trade:" + TipoTrade+ " Entrando con Posiciones activas: " + Position.Quantity.ToString());
// Exit from positions on next bar :(
ExitShort ( );
// Control Var
TipoTrade = "Libre";
// message to Alert Windows
Alert("MyAlert2", Priority.High, "Saliendo de una Venta. Estado Bandera: " + TipoTrade , @"C:\Archivos de Programa\NinjaTrader 6\sounds\Alert2.wav", 60, Color.LightPink, Color.Black);

}

NinjaTrader_Ray
11-08-2007, 07:27 AM
Please see the property CalculateOnBarClose.

http://www.ninjatrader-support.com/HelpGuideV6/CalculateOnBarClose1.html

Agamenon
11-08-2007, 07:39 AM
Thx! Itīs Possible! If my indicators support it!

Agamenon
11-08-2007, 09:28 AM
Ok, I put CalculateOnBarClose = false; in my Initialize(), no problem, but the ExitShort and ExitLong orders, execute in next bar, not in current bar or bar in progress! :confused: Itīs possible to exit inmediatly with current bar, donīt wait to next bar, to execute exits commands?

NinjaTrader_Ray
11-08-2007, 09:35 AM
Is this in backtest or in real-time?

Agamenon
11-08-2007, 09:50 AM
In Real Time. :)

NinjaTrader_Josh
11-08-2007, 10:36 AM
Hi Agamenon,

For clarification, are the Print commands you call being executed on the bar you want the Exit orders to be sent or are they also printing on the next bar? Add Time[0] into the output string to see what time the Print command is executed.

Agamenon
11-08-2007, 01:18 PM
Hi Josh,

I Will check and reforced Time[0], thanks for the help! :)

Now I think that the command, the parameter 1, for 1 bar ago will be 0!:

( CrossAbove(KPA900(), KPAutoStop(), 1)

I will change for it:

( CrossAbove(KPA900(), KPAutoStop(), 0)

could be it the event that lag the exitshort-long?

I will take note of all events and time and will post again!

Thx!

KBJ
11-08-2007, 09:17 PM
All of the examples in the help for CrossAbove and CrossBelow specify "1" as the smallest parameter value for "lookBackPeriod", so I had assumed that this was the smallest value one could use for the parameter.

Is a value of zero valid for this parameter?

NinjaTrader_Josh
11-08-2007, 09:22 PM
You would normally use 1. I suspect it is simply your indicators not crossing till the end of the bar. You can check this by printing out the values of the indicators.

If you do a crossabove on say SMA(5) over SMA(20) you will see it executes immediately if you have CalculateOnBarClose=false

Agamenon
11-09-2007, 08:32 AM
OK, I check CrossBelow//Above with 0 instead of 1, and dont work :( .

But I try with 1 and Work perfectly! :) 2 o 3 seconds of delay, but work properly. Thanks to all!!! :)


The checks in debug with Print(), Time[0] and the ExitLong/Short, show that command executed with the indicator, all work perfectly in Real Time.

Another Question: What command or method i use for delays? Thread.Sleep() work???

NinjaTrader_Ray
11-09-2007, 10:26 AM
We highly advise NOT to handle any threads in the application. This can have adverse affects on NinjaTrader.

RandyT
09-28-2008, 12:50 AM
I have a strategy that I am working on that is looking for crosses from two values of an indicator. Entries seem to be working as expected, but the Exits are missing crosses of the two variables and therefore missing the exits.

Is there something I should be looking for to get the behavior on the exits?

Here is the code:

// Long Entry
if ((CrossAbove(RMO(2,10,30,81).ST1, 25, 2)) &&
(RMO(2,10,30,81).ST4[0] > 0))

{
EnterLongLimit(GetCurrentBid(), "RMO Long Entry");
}

// Long Exit
if ((CrossBelow(RMO(2,10,30,81).ST1, RMO(2,10,30,81).ST3, 1)) &&
(CrossBelow(RMO(2,10,30,81).ST1, RMO(2,10,30,81).ST2, 1)) &&
(Position.MarketPosition == MarketPosition.Long))
{
ExitLong("RMO Long Entry");
}

NinjaTrader_Ben
09-28-2008, 01:18 AM
Hello,

I am sorry, I am not familiar with the RMO indicator.

I suggest testing the logic with a default indicator and see if the logic is correct. If it works with a default indicator I would check the custom indicator values.

Also try using Print() and TradeOrders to debug:
http://www.ninjatrader-support.com/vb/showthread.php?t=3418