NexusFi: Find Your Edge


Home Menu

 





Logical error in the strategy based on open types


Discussion in EasyLanguage Programming

Updated
    1. trending_up 2,324 views
    2. thumb_up 4 thanks given
    3. group 1 followers
    1. forum 7 posts
    2. attach_file 4 attachments




 
Search this Thread

Logical error in the strategy based on open types

  #1 (permalink)
Alexlaxmikant
India
 
Posts: 18 since May 2010
Thanks Given: 39
Thanks Received: 8

Hi,
I am facing some logical error in below code
 
Code
inputs:timeopen(0945);
vars:  od(0);
od = (h-l)*4/5 ;
condition1 = (h-l) >= ((o - l) + od) ;
condition2 = close>open and (h-l)> average((h-l),10);
condition3 = low> low[1] + ((h[1]-l[1])/2) and c >c[1];
if time < timeopen then 
begin
if condition1 and condition2 and condition3 then buy 
this bar at close;
end;
if time<time[1] then begin
value1 = barssinceentry(1);
if value1 >=4 and value1<8 and high> highest(h,3)[1] then buy 
("fe") 2 shares next bar at market; 
end;
setexitonclose;
Logic is, first three conditions defines open type ( in this code it is open drive) in first half an hour after session open.
so far so good, no problem,
Now problem arises with second part of the logic, I want to buy highest high of last 5 bars ( tf is 15 min ) after 1 hr of the session start when above three conditions ( condition1, condition2 and condition3) are true.
Ex. Market opene at 9 am by 9.30 we get signal as open drive. We wait for an hour then afterwords wait for the opportunity to buy when high is greater than highest high of last 5 bars {( h >(h,5)[1]} but MC cant let it happen
because among previous three conditions there is one parameter which says time <0930 ( i.e. time is less than 9.30 am ) so all the code stop working after 9.30am
I have tried barssince entry, barcount = barcount+1 etc but it's somehow not working, I can compile the code but it doesnt reflect on chart as per logic.
posting the chart for reference..

[IMG]http://img833.imageshack.us/img833/7120/querryoncode.jpg[/IMG]

Uploaded with ImageShack.us..

Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Deepmoney LLM
Elite Quantitative GenAI/LLM
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Exit Strategy
NinjaTrader
Futures True Range Report
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
Battlestations: Show us your trading desks!
26 thanks
The Program
18 thanks
  #3 (permalink)
 
Jura's Avatar
 Jura   is a Vendor
 
Posts: 775 since Apr 2010
Thanks Given: 2,352
Thanks Received: 690


Hi Alex,

I've slightly changed your code and added some comments inside it (see those comments for what might still be wrong with the code). I've added a check that the time should be more than one hour after the open, and then, if condition1-3 are true, a limit order is submitted for the highest price of the last 5 bars, excluding the current bar.

Do note that the 'Highest(High, 5)[1]' part means that every bar the limit price can change (since the highest high is recalculated on each bar), which can mean that you have trouble getting the limit order filled.
 
Code
inputs:
    timeopen(0945);

vars:  
    od(0), highestHigh(0);

od = (h-l) * 4/5;

condition1 = (High - Low) >= ((Open - Low) + od) ;
condition2 = Close > Open and (High - Low)> Average((High - Low),10);
condition3 = low > ( low[1] + ((High[1] - Low[1]) / 2) ) and Close > Close[1];

// Opening the 'open drive' position
if time < timeopen then begin
    if condition1 and condition2 and condition3 then 
        buy ("od") this bar at close;                    // PS: Buying at the close can in a backtest, but not in real-time/demo trading
end;

{
    I want to buy highest high of last 5 bars ( tf is 15 min ) after 1 hr of the session start when 
    above three conditions ( condition1, condition2 and condition3) are true. 
}
highestHigh = Highest(High, 5)[1];

if (Time > (timeOpen + 100))        // Open a position if it's later than 1045
        and (condition1 = true) and (condition2 = true) and (condition3 = true) then
    
        Buy ("fe#2") 2 shares next bar at highestHigh limit;

if time < time[1] then begin                    // Isn't this statement always true?

    value1 = barssinceentry(1);
    if value1 >=4 and value1<8 and high> highest(h,3)[1] then 
        buy ("fe") 2 shares next bar at market; 

end;

setexitonclose;
Also, with multiple entries, be sure to check this checkbox:



Example of above code (I don't know if this is what you intended it to do?):


Reply With Quote
Thanked by:
  #4 (permalink)
Alexlaxmikant
India
 
Posts: 18 since May 2010
Thanks Given: 39
Thanks Received: 8

Thanks Jura for the time and effort. I applied the indicator edited by you but it's still giving the poblem. I am feeling that might be my MC is corrupted, to verify could you please try it on your end, I have attached the data.
First please apply this indicator on the data that i have attached, it will show OD(open drive) as text on the chart.

 
Code
inputs:timeopen(0945);
vars: od(0);
od = (h-l)*4/5 ;
condition1 = (h-l) >= ((o - l) + od) and
 time<= timeopen;
condition2 = close>open and (h-l)> average((h-l),10);
condition3 = low> low[1] + ((h[1]-l[1])/2) and c >c[1];
if condition1 and condition2 and condition3 then
value1 = text_new ( date, time, open, "OD");
Now apply your indicator, whenever there is OD printed only on at that day our strategy suppose to execute.
Here how it look in my window

[IMG]http://img831.imageshack.us/img831/6911/bmtiindictr.jpg[/IMG]

Uploaded with ImageShack.us

Attached Files
Elite Membership required to download: temp data bmt.rar
Reply With Quote
Thanked by:
  #5 (permalink)
 
Jura's Avatar
 Jura   is a Vendor
 
Posts: 775 since Apr 2010
Thanks Given: 2,352
Thanks Received: 690


Alexlaxmikant View Post
Thanks Jura for the time and effort. I applied the indicator edited by you but it's still giving the poblem. I am feeling that might be my MC is corrupted, to verify could you please try it on your end, I have attached the data.
First please apply this indicator on the data that i have attached, it will show OD(open drive) as text on the chart.

 
Code
inputs:timeopen(0945);
vars: od(0);
od = (h-l)*4/5 ;
condition1 = (h-l) >= ((o - l) + od) and
 time<= timeopen;
condition2 = close>open and (h-l)> average((h-l),10);
condition3 = low> low[1] + ((h[1]-l[1])/2) and c >c[1];
if condition1 and condition2 and condition3 then
value1 = text_new ( date, time, open, "OD");
Now apply your indicator, whenever there is OD printed only on at that day our strategy suppose to execute.
Here how it look in my window

Hi Alex,

If I attach that indicator to my chart and then the strategy from the earlier post, I get this:



That looks good right? (where the 'OD' text appeared I've drawn a lightblue arrow to spot it easier) Or do you don't want the "fe#2" orders been shown?

Reply With Quote
  #6 (permalink)
Alexlaxmikant
India
 
Posts: 18 since May 2010
Thanks Given: 39
Thanks Received: 8

Hi Jura,
Thank you so much for your time and quick replies, seems like we will get the solution. Here in your chart buy signal appears on the same bar where OD( Open Drive) appears. Once we get the confirmation of Open Drive then after we suppose to enter the market when high is higher than highest(h,4)[1] ( MC calculate from left so shouldn't be any problem) I can understand that fe#2 is there for teh same purpose but it triggers even though there is no open drive at the start of session.
P.S. to complete the strategy stop loss would be l<lowest(l,5); When I saw it visually felt promising stuff so thats why putting so much effort. Once this done then there are codes ready for other open types and based on OD module could code easily for other open types.

Reply With Quote
  #7 (permalink)
Alexlaxmikant
India
 
Posts: 18 since May 2010
Thanks Given: 39
Thanks Received: 8

I was trying to debug the code one structure at a time, and seems like problem lies in time< time[1] ( or date<> date[1] ) line. Here is an experiment..
Run this code without time<time[1] ( or date<> date[1] )

 
Code
vars: highesthi(0);
if time>0900 and time<1500 {and date<>date[1]}
then begin
highesthi = highest(high[1],5);

if high>highesthi then buy next bar at market;
end;
setexitonclose;
you will get accurate signals
now add time>time[1] or date<>date[1] linr
 
Code
vars: highesthi(0);
if time>0900 and time<1500 and date<>date[1]
then begin
highesthi = highest(high[1],5);

if high>highesthi then buy next bar at market;
end;
setexitonclose;
now see the chart, it give erratic signals.
I can't understand why this is happening.

Reply With Quote
  #8 (permalink)
Alexlaxmikant
India
 
Posts: 18 since May 2010
Thanks Given: 39
Thanks Received: 8

Update
Issue resolved. As Jura posted it correctly by avoiding date<>date[1] filter.
This happens because the command date<>date[1] is only useful for first bar of the day, from second bar of the day this filter has no meaning at all as it only stores information for the first bar of the day.
Better way to code intraday strategy is using only time filter
Inputs: MarketOpen(0915),MarketClose(1530);
if time > MarketOpen and time < MarketClose then begin

Reply With Quote




Last Updated on May 2, 2012


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts