Issues with counting number of trades - futures io
futures io



Issues with counting number of trades


Discussion in EasyLanguage Programming

Updated
    1. trending_up 353 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 2 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 150,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Issues with counting number of trades

(login for full post details)
  #1 (permalink)
 Iluvchocmilk 
Portland
 
Experience: Beginner
Platform: TradingView
Broker: Tradestation
Trading: Emini ES
 
Posts: 49 since Jul 2020
Thanks: 32 given, 37 received

Hello,

I am having issues with my code not limiting the number of trades in the short direction even though it appears to be working in the long direction.

My original approach was using the BuysToday and ShortsToday counter which was working but then I noticed it was taking more than one trade in the short direction. I then started trying to debug it and tried the TradeCounter approach but that isn't working either. I am wondering if there is a problem I am just missing to see in the code.

Here is an image showing how it is taking more than one short position after the previous one stopped out. Is it registering that it is in fact flat because it stopped out therefore it is flat?





Inputs: StopAmt(15), ProfitAmt(80), MaxTrades(2);

Vars: timestart(0640), timeend(1300), RangeHigh(0),RangeLow(0), BuysToday(0), ShortsToday(0), TradeCounter(0), MP(0);
MP=Marketposition;

If ( MP <> 0 ) and (MP[1] <> MP ) then TradeCounter = TradeCounter+ 1; //Checks to see change in state
if Marketposition=1 then BuysToday=1; //Increments to 1 if there is an open trade
if Marketposition=-1 then ShortsToday=1; //Increments to 1 if there is an open trade

if time >=630 and time <=640 then
Begin
RangeHigh=Highest(High,2); //Defines high of range
RangeLow=Lowest(Low,2); //Defines low of the range
BuysToday=0; ShortsToday=0; TradeCounter=0; //Resets trade counter to zero on the open
End;

If time>=timestart and time <timeend then
Begin
If TradeCounter<MaxTrades and close<RangeLow then Sell Short 1 contracts next bar at market;

If BuysToday=0 and close>RangeHigh then Buy 1 contracts next bar at market;

SetStopLoss(StopAmt);
SetProfitTarget(ProfitAmt);
end;

//TradeCounter<MaxTrades

Visit my futures io Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on futures io?
value chart indicator by sim22
NinjaTrader
mahDualCandlePattern
NinjaTrader
Time to change of FCM
Emini and Emicro Index
Multidata
EasyLanguage Programming
Tick Data Group Buy
Emini and Emicro Index
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Spoo-nalysis ES e-mini futures S&P 500
97 thanks
Most Funding Firms are a Scam
65 thanks
Hedging NQ and MNQ 1-10...
13 thanks
Trading Plan
9 thanks
How many day traders are profitable?
8 thanks
 
(login for full post details)
  #2 (permalink)
 kevinkdog   is a Vendor
 
 
Posts: 3,305 since Jul 2012
Thanks: 1,750 given, 6,664 received

It looks like all your short trades (except last one) entered and exited on the same bar. So the MarketPosition keyword would never get updated - things only get updated at end of the bar.

I tried adjusting your code, I did not verify or test this, but I did the buy and sell trade counter differently. Maybe this will work better for you.

 
Code
Inputs: StopAmt(15), ProfitAmt(80), MaxTrades(2);

Vars: timestart(0640), timeend(1300), RangeHigh(0),RangeLow(0), BuysToday(0), ShortsToday(0), TradesAtStart(0);


if time >=630 and time <=640 then
Begin
RangeHigh=Highest(High,2); //Defines high of range
RangeLow=Lowest(Low,2); //Defines low of the range
BuysToday=0; ShortsToday=0; TradesAtStart=TotalTrades; //Resets trade counter to zero on the open
End;

If time>=timestart and time <timeend then
Begin
If TradesAtStart-TotalTrades<MaxTrades and ShortsToday<>1 and close<RangeLow then begin
 Sell Short 1 contracts next bar at market;
 ShortsToday=1;
end;

If TradesAtStart-TotalTrades<MaxTrades and BuysToday<>1  and close>RangeHigh then begin
 Buy 1 contracts next bar at market;
 BuysToday=1;
end;

SetStopLoss(StopAmt);
SetProfitTarget(ProfitAmt);
end;

If it doesn't work, give me some exact chart details of where it is a problem, and I can debug easier...

Follow me on Twitter Reply With Quote
The following user says Thank You to kevinkdog for this post:
 
(login for full post details)
  #3 (permalink)
 Iluvchocmilk 
Portland
 
Experience: Beginner
Platform: TradingView
Broker: Tradestation
Trading: Emini ES
 
Posts: 49 since Jul 2020
Thanks: 32 given, 37 received



kevinkdog View Post
It looks like all your short trades (except last one) entered and exited on the same bar. So the MarketPosition keyword would never get updated - things only get updated at end of the bar.

I tried adjusting your code, I did not verify or test this, but I did the buy and sell trade counter differently. Maybe this will work better for you.

 
Code
Inputs: StopAmt(15), ProfitAmt(80), MaxTrades(2);

Vars: timestart(0640), timeend(1300), RangeHigh(0),RangeLow(0), BuysToday(0), ShortsToday(0), TradesAtStart(0);


if time >=630 and time <=640 then
Begin
RangeHigh=Highest(High,2); //Defines high of range
RangeLow=Lowest(Low,2); //Defines low of the range
BuysToday=0; ShortsToday=0; TradesAtStart=TotalTrades; //Resets trade counter to zero on the open
End;

If time>=timestart and time <timeend then
Begin
If TradesAtStart-TotalTrades<MaxTrades and ShortsToday<>1 and close<RangeLow then begin
 Sell Short 1 contracts next bar at market;
 ShortsToday=1;
end;

If TradesAtStart-TotalTrades<MaxTrades and BuysToday<>1  and close>RangeHigh then begin
 Buy 1 contracts next bar at market;
 BuysToday=1;
end;

SetStopLoss(StopAmt);
SetProfitTarget(ProfitAmt);
end;

If it doesn't work, give me some exact chart details of where it is a problem, and I can debug easier...


@kevinkdog Thanks for the reply.

Do you know if the TotalTrades function counts the total number of trades for all the data you have loaded or just the total number of trades on the current day?

The EL reference PDF doesn't specify.

TotalTrades


Otherwise it does seem like the markeposition not calculating until the end of the bar was issue.

Visit my futures io Trade Journal Started this thread Reply With Quote
 
(login for full post details)
  #4 (permalink)
 Iluvchocmilk 
Portland
 
Experience: Beginner
Platform: TradingView
Broker: Tradestation
Trading: Emini ES
 
Posts: 49 since Jul 2020
Thanks: 32 given, 37 received

@kevinkdog I answered my own question there haha

If it only calculated the trades for the day, you wouldn't need the TradesAtStart-TotalTrades logic in the code.

Visit my futures io Trade Journal Started this thread Reply With Quote
The following user says Thank You to Iluvchocmilk for this post:


futures io Trading Community Platforms and Indicators EasyLanguage Programming > Issues with counting number of trades


Last Updated on May 8, 2022


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
     



Copyright © 2022 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), info@futures.io
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.
no new posts