NexusFi: Find Your Edge


Home Menu

 





About Easylanguage Time Management for Entering Trades


Discussion in EasyLanguage Programming

Updated
    1. trending_up 5,221 views
    2. thumb_up 3 thanks given
    3. group 1 followers
    1. forum 10 posts
    2. attach_file 3 attachments




 
Search this Thread

About Easylanguage Time Management for Entering Trades

  #1 (permalink)
M4STR0
Florence
 
Posts: 27 since Jan 2021
Thanks Given: 23
Thanks Received: 9

Hello, I am quite new to easy language, recently I wrote to exercise myself, this Signal in Multicharts to enter a trade at given day of week in a given hour in the inputs for the SP future 30 minutes chart, and exit the trade at another day of week and hour.
 
Code
input: NContracts(1),
	MyTimeEntry(1200),
	MyTimeExit(1200),
	Mystop(1000),
	Myprofit(0),
	MyBeginningDay(1),
	MyEndingDay(3);

if dayofweek(date) = MyBeginningDay and Time = MyTimeEntry then begin

	Buy ("Bias_Long") NContracts contracts this bar on close;

end;

if dayofweek(date) = MyEndingDay and Time = MyTimeExit then begin

	if marketposition <> 0 then sellshort ("Time_Exit_L") next bar high limit;
	
end;

if mystop > 0 then setstoploss(mystop);
if myprofit > 0 then setprofittarget(myprofit);
Basically it never enter the trade on Monday, I also tryed to optimize for MyBeginningDay and it never feels like it is Monday = 1...Same thing with the hour it randomly take a different hour to exit the trade on the same day most of the time.

I have quite an headache understating what can be the problem for this simple and stupid code.
I am also sure I setup properly symbol session time in quote manager, using exchange session time zone. And I also removed holidays.

-Are the bars provided by IQfeed not properly set? or is it because I am doing something wrong with the code or datafeed?

-Is there some difference between datafeed exchange time, local time and bars time?

-Any suggestions to improve the code and make it work as intended?

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
Exit Strategy
NinjaTrader
Better Renko Gaps
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
GFIs1 1 DAX trade per day journal
10 thanks
Diary of a simple price action trader
10 thanks
  #2 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,662 since Jul 2012
Thanks Given: 1,892
Thanks Received: 7,351

I tried it, and got plenty of Monday entries (I added one print statement so you can see):

 
Code
input: NContracts(1),
	MyTimeEntry(1200),
	MyTimeExit(1200),
	Mystop(1000),
	Myprofit(0),
	MyBeginningDay(1),
	MyEndingDay(3);

if dayofweek(date) = MyBeginningDay and Time = MyTimeEntry then begin
    If MyBeginningDay=1  then print ("buy on Monday ", date);
	Buy ("Bias_Long") NContracts contracts this bar on close;

end;

if dayofweek(date) = MyEndingDay and Time = MyTimeExit then begin

	if marketposition <> 0 then sellshort ("Time_Exit_L") next bar high limit;
	
end;

if mystop > 0 then setstoploss(mystop);
if myprofit > 0 then setprofittarget(myprofit);


buy on Monday 1200106.00
buy on Monday 1200113.00
buy on Monday 1200120.00
buy on Monday 1200127.00
buy on Monday 1200203.00
buy on Monday 1200210.00
buy on Monday 1200217.00
buy on Monday 1200224.00
buy on Monday 1200302.00
buy on Monday 1200309.00
buy on Monday 1200316.00
buy on Monday 1200323.00
buy on Monday 1200330.00
buy on Monday 1200406.00
buy on Monday 1200413.00
buy on Monday 1200420.00
buy on Monday 1200427.00
buy on Monday 1200504.00
buy on Monday 1200511.00
buy on Monday 1200518.00
buy on Monday 1200525.00
buy on Monday 1200601.00
buy on Monday 1200608.00
buy on Monday 1200615.00
buy on Monday 1200622.00
buy on Monday 1200629.00
buy on Monday 1200706.00
buy on Monday 1200713.00
buy on Monday 1200720.00
buy on Monday 1200727.00
buy on Monday 1200803.00
buy on Monday 1200810.00
buy on Monday 1200817.00
buy on Monday 1200824.00
buy on Monday 1200831.00
buy on Monday 1200907.00
buy on Monday 1200914.00
buy on Monday 1200921.00
buy on Monday 1200928.00
buy on Monday 1201005.00
buy on Monday 1201012.00
buy on Monday 1201019.00
buy on Monday 1201026.00
buy on Monday 1201102.00
buy on Monday 1201109.00
buy on Monday 1201116.00
buy on Monday 1201123.00
buy on Monday 1201130.00
buy on Monday 1201207.00
buy on Monday 1201214.00
buy on Monday 1201221.00
buy on Monday 1201228.00



I also optimized for Entry hour, and got plenty of entries every hour...


Follow me on Twitter Reply With Quote
Thanked by:
  #3 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT and Stellar
Broker: Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,048 since Dec 2013
Thanks Given: 4,384
Thanks Received: 10,206



M4STR0 View Post
 
Code
if dayofweek(date) = MyEndingDay and Time = MyTimeExit then begin
	if marketposition <> 0 then sellshort ("Time_Exit_L") next bar high limit;

Sellshort is reversing your trade from long to short, not just exiting the position. To exit and not reverse just use sell.

Reply With Quote
Thanked by:
  #4 (permalink)
M4STR0
Florence
 
Posts: 27 since Jan 2021
Thanks Given: 23
Thanks Received: 9

Thank you Kevinkdog and SMCJB, but I guess something is wrong with multicharts, once I have tradestation I will also test this in that platform perhaps it is just a problem of multicharts and iqfeed bar data. Did not know about the difference between sellshort and sell, thank you this was helpful.

Reply With Quote
  #5 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,662 since Jul 2012
Thanks Given: 1,892
Thanks Received: 7,351


M4STR0 View Post
Thank you Kevinkdog and SMCJB, but I guess something is wrong with multicharts, once I have tradestation I will also test this in that platform perhaps it is just a problem of multicharts and iqfeed bar data. Did not know about the difference between sellshort and sell, thank you this was helpful.


I get the same results in MultiCharts - I cannot duplicate the issues you mentioned.

Follow me on Twitter Reply With Quote
  #6 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT and Stellar
Broker: Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,048 since Dec 2013
Thanks Given: 4,384
Thanks Received: 10,206


M4STR0 View Post
Did not know about the difference between sellshort and sell, thank you this was helpful.

Buy and Sellshort enter new positions. If you currently have a position in the opposite direction it will both close it and enter the new position (ie reverse the position).
Buytocover and Sell will only close positions.

Reply With Quote
Thanked by:
  #7 (permalink)
M4STR0
Florence
 
Posts: 27 since Jan 2021
Thanks Given: 23
Thanks Received: 9

I did some further investigations by doing some sane debugging, I added this
 
Code
print(datetimetostring(datetime), "	", "dayofweek(d):", dayofweek(d),"		", "Time:", Time,"	", "dayofweek(date):", dayofweek(date));
to the signal and rewrote it a bit like this:
 
Code
input: NContracts(1);
input:	MyTimeEntry(2200), MyTimeExit(2200);
input: MyBeginningDay(1), MyEndingDay(3);
input:	Mystop(0), Myprofit(0), MyBreakeven(0);

print(datetimetostring(datetime), "	", "dayofweek(d):", dayofweek(d),"		", "Time:", Time,"	", "dayofweek(date):", dayofweek(date));

if Time = MyTimeEntry and dayofweek(d) = MyBeginningDay then buy ("Bias_Long") NContracts contracts next bar market;
if Time = MyTimeExit and dayofweek(d) = MyEndingDay then sell ("Bias_Short") NContracts contracts next bar at market;

setstopcontract;

if MyStop > 0 then setstoploss(Mystop);
if MyBreakeven > 0 then setbreakeven(MyBreakeven);
if MyProfit > 0 then setprofittarget(MyProfit);
The debuggin output is interesting
30/09/2020 05:00:00 dayofweek(d): 3.00 Time: 500.00 dayofweek(date): 3.00
30/09/2020 06:00:00 dayofweek(d): 3.00 Time: 600.00 dayofweek(date): 3.00
30/09/2020 09:00:00 dayofweek(d): 3.00 Time: 900.00 dayofweek(date): 3.00
01/10/2020 20:00:00 dayofweek(d): 4.00 Time:2000.00 dayofweek(date): 4.00
02/10/2020 04:00:00 dayofweek(d): 5.00 Time: 400.00 dayofweek(date): 5.00
02/10/2020 05:00:00 dayofweek(d): 5.00 Time: 500.00 dayofweek(date): 5.00
02/10/2020 06:00:00 dayofweek(d): 5.00 Time: 600.00 dayofweek(date): 5.00
02/10/2020 07:00:00 dayofweek(d): 5.00 Time: 700.00 dayofweek(date): 5.00
02/10/2020 08:00:00 dayofweek(d): 5.00 Time: 800.00 dayofweek(date): 5.00
07/10/2020 02:00:00 dayofweek(d): 3.00 Time: 200.00 dayofweek(date): 3.00
07/10/2020 08:00:00 dayofweek(d): 3.00 Time: 800.00 dayofweek(date): 3.00
08/10/2020 08:00:00 dayofweek(d): 4.00 Time: 800.00 dayofweek(date): 4.00
09/10/2020 02:00:00 dayofweek(d): 5.00 Time: 200.00 dayofweek(date): 5.00
09/10/2020 03:00:00 dayofweek(d): 5.00 Time: 300.00 dayofweek(date): 5.00
12/10/2020 04:00:00 dayofweek(d): 1.00 Time: 400.00 dayofweek(date): 1.00
12/10/2020 09:00:00 dayofweek(d): 1.00 Time: 900.00 dayofweek(date): 1.00
14/10/2020 06:00:00 dayofweek(d): 3.00 Time: 600.00 dayofweek(date): 3.00
14/10/2020 08:00:00 dayofweek(d): 3.00 Time: 800.00 dayofweek(date): 3.00
15/10/2020 05:00:00 dayofweek(d): 4.00 Time: 500.00 dayofweek(date): 4.00
15/10/2020 07:00:00 dayofweek(d): 4.00 Time: 700.00 dayofweek(date): 4.00
15/10/2020 08:00:00 dayofweek(d): 4.00 Time: 800.00 dayofweek(date): 4.00
16/10/2020 08:00:00 dayofweek(d): 5.00 Time: 800.00 dayofweek(date): 5.00
21/10/2020 07:00:00 dayofweek(d): 3.00 Time: 700.00 dayofweek(date): 3.00
21/10/2020 19:00:00 dayofweek(d): 3.00 Time:1900.00 dayofweek(date): 3.00
26/10/2020 04:00:00 dayofweek(d): 1.00 Time: 400.00 dayofweek(date): 1.00
27/10/2020 18:00:00 dayofweek(d): 2.00 Time:1800.00 dayofweek(date): 2.00
28/10/2020 04:00:00 dayofweek(d): 3.00 Time: 400.00 dayofweek(date): 3.00
28/10/2020 16:00:00 dayofweek(d): 3.00 Time:1600.00 dayofweek(date): 3.00
29/10/2020 06:00:00 dayofweek(d): 4.00 Time: 600.00 dayofweek(date): 4.00
29/10/2020 07:00:00 dayofweek(d): 4.00 Time: 700.00 dayofweek(date): 4.00
29/10/2020 09:00:00 dayofweek(d): 4.00 Time: 900.00 dayofweek(date): 4.00
30/10/2020 04:00:00 dayofweek(d): 5.00 Time: 400.00 dayofweek(date): 5.00
30/10/2020 05:00:00 dayofweek(d): 5.00 Time: 500.00 dayofweek(date): 5.00
30/10/2020 07:00:00 dayofweek(d): 5.00 Time: 700.00 dayofweek(date): 5.00
30/10/2020 08:00:00 dayofweek(d): 5.00 Time: 800.00 dayofweek(date): 5.00
02/11/2020 04:00:00 dayofweek(d): 1.00 Time: 400.00 dayofweek(date): 1.00
02/11/2020 06:00:00 dayofweek(d): 1.00 Time: 600.00 dayofweek(date): 1.00
02/11/2020 09:00:00 dayofweek(d): 1.00 Time: 900.00 dayofweek(date): 1.00
04/11/2020 02:00:00 dayofweek(d): 3.00 Time: 200.00 dayofweek(date): 3.00
05/11/2020 09:00:00 dayofweek(d): 4.00 Time: 900.00 dayofweek(date): 4.00
06/11/2020 04:00:00 dayofweek(d): 5.00 Time: 400.00 dayofweek(date): 5.00
06/11/2020 07:00:00 dayofweek(d): 5.00 Time: 700.00 dayofweek(date): 5.00
06/11/2020 08:00:00 dayofweek(d): 5.00 Time: 800.00 dayofweek(date): 5.00
09/11/2020 06:00:00 dayofweek(d): 1.00 Time: 600.00 dayofweek(date): 1.00
09/11/2020 08:00:00 dayofweek(d): 1.00 Time: 800.00 dayofweek(date): 1.00
11/11/2020 07:00:00 dayofweek(d): 3.00 Time: 700.00 dayofweek(date): 3.00
12/11/2020 08:00:00 dayofweek(d): 4.00 Time: 800.00 dayofweek(date): 4.00
16/11/2020 07:00:00 dayofweek(d): 1.00 Time: 700.00 dayofweek(date): 1.00
19/11/2020 06:00:00 dayofweek(d): 4.00 Time: 600.00 dayofweek(date): 4.00
23/11/2020 08:00:00 dayofweek(d): 1.00 Time: 800.00 dayofweek(date): 1.00
25/11/2020 00:00:00 dayofweek(d): 3.00 Time: 0.00 dayofweek(date): 3.00
25/11/2020 01:00:00 dayofweek(d): 3.00 Time: 100.00 dayofweek(date): 3.00
25/11/2020 02:00:00 dayofweek(d): 3.00 Time: 200.00 dayofweek(date): 3.00
25/11/2020 16:00:00 dayofweek(d): 3.00 Time:1600.00 dayofweek(date): 3.00
25/11/2020 20:00:00 dayofweek(d): 3.00 Time:2000.00 dayofweek(date): 3.00
25/11/2020 23:00:00 dayofweek(d): 3.00 Time:2300.00 dayofweek(date): 3.00
27/11/2020 06:00:00 dayofweek(d): 5.00 Time: 600.00 dayofweek(date): 5.00
29/11/2020 18:00:00 dayofweek(d): 0.00 Time:1800.00 dayofweek(date): 0.00
30/11/2020 09:00:00 dayofweek(d): 1.00 Time: 900.00 dayofweek(date): 1.00
11/12/2020 08:00:00 dayofweek(d): 5.00 Time: 800.00 dayofweek(date): 5.00
13/12/2020 22:00:00 dayofweek(d): 0.00 Time:2200.00 dayofweek(date): 0.00
16/12/2020 09:00:00 dayofweek(d): 3.00 Time: 900.00 dayofweek(date): 3.00
16/12/2020 16:00:00 dayofweek(d): 3.00 Time:1600.00 dayofweek(date): 3.00
17/12/2020 20:00:00 dayofweek(d): 4.00 Time:2000.00 dayofweek(date): 4.00
18/12/2020 09:00:00 dayofweek(d): 5.00 Time: 900.00 dayofweek(date): 5.00
21/12/2020 06:00:00 dayofweek(d): 1.00 Time: 600.00 dayofweek(date): 1.00

for starters the data I got ends the 21/12/2020 and looks like the day 1.00 of the week never gets to hour 22000...
Perhaps for Monday I have to use day 0 instead of 1

Reply With Quote
  #8 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,662 since Jul 2012
Thanks Given: 1,892
Thanks Received: 7,351

It goes off of your chart time, so that is what I'd check.

Follow me on Twitter Reply With Quote
  #9 (permalink)
M4STR0
Florence
 
Posts: 27 since Jan 2021
Thanks Given: 23
Thanks Received: 9

I am using this session time settings now, before I saw I did a mistake between the days

Open Time Close Time Session End

Sunday 17:00 Monday 16:00 X
Monday 17:00 Tuesday 16:00 X
Tuesday 17:00 Wednesday 16:00 X
Wedsnesday 17:00 Thurdsday 16:00 x
Thurdsday 17:00 Friday 16:00 x

and Exchange time in the instrument chart settings for the SP future

Anyway, now that I fixed the session time settings I see it still does not start most of the time in monday, this is really weird.

Attached Thumbnails
Click image for larger version

Name:	image_907.png
Views:	166
Size:	23.4 KB
ID:	307934   Click image for larger version

Name:	image_241.png
Views:	170
Size:	27.8 KB
ID:	307935  
Reply With Quote
  #10 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,662 since Jul 2012
Thanks Given: 1,892
Thanks Received: 7,351


Something is goofy here, because if you are using 30 minute bars, you should have a print statement printing out every 30 minutes. You don't have any print statements at 630, 730 etc, and you are missing a lot of bars at 00 times.

Follow me on Twitter Reply With Quote




Last Updated on January 5, 2021


© 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