zoltran
04-11-2007, 05:57 AM
I am having a problem with BarSinceEntry()
It's returning some large numbers that don't seem to make sense?
The strategy places an order, and then uses barsSinceEntry to adjust the stop technique.
Here's a code snippet
// Entry logic
EnterShort(DefaultQuantity, "S2_S");
PBHigh = High[1] + 2*TickSize;
PBHigh = Math.Min(PBHigh,High[0]+(15*TickSize));
Print(Instrument.FullName+" New Short, Entry is "+ Close.ToString()[0]);
Print(Instrument.FullName+" New Short, Prior Bar High= "+High.ToString()[1]+ " Stop Loss = "+ PBHigh.ToString());
SetStopLoss(CalculationMode.Price, PBHigh);
. . .
// Stop Logic
if (Position.MarketPosition == MarketPosition.Long && FirstTickOfBar)
{
Print(Instrument.FullName+" In Long,Bars = "+ BarsSinceEntry().ToString());
//Set new Stop Loss if (BarsSinceEntry() > 5)
if ( BarsSinceEntry() >5 )
{
....
}
else Print(Instrument.FullName+" In Long, Less than >5 bars = ");
And the resulting log/trace. It's just one bar away, but shows 6648 bars since entry.
fwiw, it seems to work correctly on the strategies first trade, but that's just a hunch at this point. Look for the text 'In Short Bars'
Entered internal PlaceOrder() method at 4/11/2007 10:48:00 AM: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=S2_S' FromEntrySignal=''
ER2 06-07 New Short, Entry is 8
ER2 06-07 New Short, Prior Bar High= 1 Stop Loss = 813.9
Entered internal SetStopTarget() method at 4/11/2007 10:48:00 AM: Type=Stop FromEntrySignal='' Mode=Price Value=813.9 Currency=0 Simulated=False
ER2 06-07 In Short,Bars = 6648
ER2 06-07 In Short, Adjusted Stop to MA = 812.631384615384
Entered internal SetStopTarget() method at 4/11/2007 10:51:00 AM: Type=Stop FromEntrySignal='' Mode=Price Value=812.631384615384 Currency=0 Simulated=False
ER2 06-07 In Short,Adjusted Target to = 807.6
Entered internal SetStopTarget() method at 4/11/2007 10:51:00 AM: Type=Target FromEntrySignal='' Mode=Price Value=807.6 Currency=0 Simulated=False
Also #1
Does Avgprice() refer to the current trade/position, or an avg for the whole day?
ie, can I use it for basing a Break-Even stop on?
Also #2
.. would you have any suggestions as to why my High.ToString() and Close.ToString()[0] are returning single digits in the output window? I thought it might be format str related, but the same syntax works elsewhere
Many thanks for putting up with my endless questions.
Zol
It's returning some large numbers that don't seem to make sense?
The strategy places an order, and then uses barsSinceEntry to adjust the stop technique.
Here's a code snippet
// Entry logic
EnterShort(DefaultQuantity, "S2_S");
PBHigh = High[1] + 2*TickSize;
PBHigh = Math.Min(PBHigh,High[0]+(15*TickSize));
Print(Instrument.FullName+" New Short, Entry is "+ Close.ToString()[0]);
Print(Instrument.FullName+" New Short, Prior Bar High= "+High.ToString()[1]+ " Stop Loss = "+ PBHigh.ToString());
SetStopLoss(CalculationMode.Price, PBHigh);
. . .
// Stop Logic
if (Position.MarketPosition == MarketPosition.Long && FirstTickOfBar)
{
Print(Instrument.FullName+" In Long,Bars = "+ BarsSinceEntry().ToString());
//Set new Stop Loss if (BarsSinceEntry() > 5)
if ( BarsSinceEntry() >5 )
{
....
}
else Print(Instrument.FullName+" In Long, Less than >5 bars = ");
And the resulting log/trace. It's just one bar away, but shows 6648 bars since entry.
fwiw, it seems to work correctly on the strategies first trade, but that's just a hunch at this point. Look for the text 'In Short Bars'
Entered internal PlaceOrder() method at 4/11/2007 10:48:00 AM: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=S2_S' FromEntrySignal=''
ER2 06-07 New Short, Entry is 8
ER2 06-07 New Short, Prior Bar High= 1 Stop Loss = 813.9
Entered internal SetStopTarget() method at 4/11/2007 10:48:00 AM: Type=Stop FromEntrySignal='' Mode=Price Value=813.9 Currency=0 Simulated=False
ER2 06-07 In Short,Bars = 6648
ER2 06-07 In Short, Adjusted Stop to MA = 812.631384615384
Entered internal SetStopTarget() method at 4/11/2007 10:51:00 AM: Type=Stop FromEntrySignal='' Mode=Price Value=812.631384615384 Currency=0 Simulated=False
ER2 06-07 In Short,Adjusted Target to = 807.6
Entered internal SetStopTarget() method at 4/11/2007 10:51:00 AM: Type=Target FromEntrySignal='' Mode=Price Value=807.6 Currency=0 Simulated=False
Also #1
Does Avgprice() refer to the current trade/position, or an avg for the whole day?
ie, can I use it for basing a Break-Even stop on?
Also #2
.. would you have any suggestions as to why my High.ToString() and Close.ToString()[0] are returning single digits in the output window? I thought it might be format str related, but the same syntax works elsewhere
Many thanks for putting up with my endless questions.
Zol