Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

binthere

Stop Trading Counter

Recommended Posts

hi guys,

using tradestation 8.8

I'm looking for a way to have my strategy stop trading for "x" amount of minutes after

"y" number of winning trades or

"z" number of loosing trades

thanks for your help!!

binthere

Share this post


Link to post
Share on other sites

Hi,

 

If you are using intraday time based charts, you can use the EasyLanguage reserved word BarInterval to count time in multiples of your chart inverval. You could also simply stop your stragegy for X bars. You can also access the PC clock to get the time that way.

 

There are reserved words for all the variables you mention in your question.

 

Best Regards,

Scott

Share this post


Link to post
Share on other sites

How much experience do you have with EasyLanguage? You can use the PositionProfit function to count the losers and winners then when you reach the count use calctime to time it. Don't forget to re-set the count at the end of the day or session. If you like I can code it up for you (no charge) but if you are experienced then this info should answer your question. Glad to help if you want me to code it.

 

Randall

Share this post


Link to post
Share on other sites

thank's for the response, i'm trying to do this baby steps, first making the strategy stop trading when a specific number of winners or loosers is hit but it seems it's not working

could someone look at the code and help me out to understand what i'm doing wrong?

thanks, binthere

Input:

NumberWinningTrades( 111 ),

NumberLosingTrades ( 111 );

 

Vars:

WinTrades( 0 ),

LosTrades( 0 ),

tradeOn (true);

 

If time = 0 then

Wintrades = NumLosTrades ;

Lostrades = NumWinTrades ;

 

IF ( Wintrades >= NumberWinningTrades) or (LosTrades >= NumberLoosingTrades) then

tradeOn (false)

else

begin

 

//strategy entries

 

//strategy exits

Share this post


Link to post
Share on other sites

Hi,

 

If that is the actual code, you are missing Begin/End after If time = 0 but time isn't ever 0 (it the time at the end of the bar), so your initialization wouldn't ever happen. Use either the Once keyword or a bool variable like needInit and then once you have done your initialization set it equal false.

 

I also assume you are incrementing the winning/losing trade counters somewhere in your code.

Share this post


Link to post
Share on other sites

Randall

well this is the first time i actually code a strategy and have no prior developing experience, i've been strugling to make this hapen if you could help me out coding it would greatly appreciate it!!

every word i've used in the above code has taken me for ever to understand it and try to implement it

cheers!!, binthere

Share this post


Link to post
Share on other sites

There are many ways to do it but I slapped this together and it should do what you want.

Could probably be done a little neater but it does verify.

 

Input: NumberWinningTrades(111), NumberLosingTrades (111), TimeOutMin(15);

 

Vars: TradeOff(FALSE), StopTime(0), StartAgainTime(0), WinTrades(0), LoseTrades(0),

LCount(0), WCount(0);

 

LoseTrades = NumLosTrades;

WinTrades = NumWinTrades;

 

//reset win/lose and TradeOff here on start of new day or firstbar after maxbarsback

//I am resetting it on new day but you can reset with anything, session time, another calctime, etc., etc.

if currentbar = 1 or date <> date[1] then begin

TradeOff = FALSE;

WCount = 0;

LCount = 0;

end;

 

//track win/lose trade count

if LoseTrades > LoseTrades[1] then LCount = LCount +1;

if WinTrades > WinTrades[1] then WCount = WCount +1;

 

//set TradeOff to TRUE and StopTime to time when win/lose trades was exceeded

if (WCount >= NumberWinningTrades) or (LCount >= NumberLosingTrades) then begin

TradeOff = TRUE;

StopTime = time;

end;

 

//calculate time to start again (add TimeOutMin to StopTime)

StartAgainTime = calctime(StopTime, TimeOutMin);

 

//reset TradeOff to FALSE after TimeOutMin to allow trading again on the same day

//reset trade counters to zero also

if TradeOff = TRUE and time > StartAgainTime then begin

TradeOff = FALSE;

WCount = 0;

LCount = 0;

end;

 

//allow entries

if TradeOff = FALSE then begin

 

//strategy entries

 

end;

Share this post


Link to post
Share on other sites

Randall, this is HUGE!!!!

thanks for your help!, i've been strugling for over a week to get to the code i had posted earlier... and to get to the code you did it would have taken me a gazillion years in a very frustrating journey.

i can't thank you enough for your help

cheers,, keep it spinning!

binthere

Share this post


Link to post
Share on other sites

Well, binthere got back to me and said the code would not start trading again after the time out. That's what I get for not testing my code :crap:. Below it is fixed and tested :-). It will reset on a change in date or exceeding the win/loss amount and will not trade for the time out period after that change. There are other ways to reset it, such as session end, session start, a specific time, etc., etc.

 

I have included the code here as a simple system that buys on one bar and exits on the next. I have also included the code (at bottom of system code) I use for de-bugging with the expert commentary. Just set the "Comm" input to true and using the expert commentary you can click anywhere on the chart to see the values at the close of that bar. Many people may also use a print statement for de-bugging but I personally prefer to use the commentary.

 

All of this goes to show something that I learned a long time ago but foolishly failed to implement here- always, always check your code to make sure it is doing what you think. More often than not code looks great and might do what you think part of the time but check, re-check, and re-check again. I hate to imagine how many great ideas have been discarded because they were coded wrong and failed.

 

I apologize for the error. ELD attached, coded in TS 8.6

 

 

Input: NumberWinningTrades(5), NumberLosingTrades (5), TimeOutMin(5), Comm(FALSE);

 

Vars: TradeOff(FALSE), StopTime(0), StartAgainTime(0), WinTrades(0), LoseTrades(0),

LCount(0), WCount(0), MP(0);

 

LoseTrades = NumLosTrades;

WinTrades = NumWinTrades;

MP = marketposition;

 

 

//reset all on date change or first bar

//you could reset here for whatever you choose

if currentbar = 1 or date <> date[1] then begin

StopTime = time;

StartAgainTime = calctime(StopTime, TimeOutMin);

TradeOff = TRUE;

WCount = 0;

LCount = 0;

end;

 

//track win/lose trade count (note reset above and date = date[1])

//will not carry count over after date change- easy to change this

if date = date[1] then begin

if LoseTrades > LoseTrades[1] then LCount = LCount +1;

if WinTrades > WinTrades[1] then WCount = WCount +1;

end;

 

//set TradeOff to TRUE and StopTime to time when win/lose trades was exceeded

if (WCount >= NumberWinningTrades) or (LCount >= NumberLosingTrades) then begin

TradeOff = TRUE;

StopTime = time;

//calculate time to start again (add TimeOutMin to StopTime)

StartAgainTime = calctime(StopTime, TimeOutMin);

WCount = 0;

LCount = 0;

end;

 

//reset TradeOff

if TradeOff = TRUE and time >= StartAgainTime then TradeOff = FALSE;

 

//allow entries

if TradeOff = FALSE then begin

 

if MP = 0 then buy next bar at market;

 

end;

 

if MP = +1 then sell next bar at market;

 

 

//beging expert commentary code used for debugging

if Comm then begin

 

Vars: Str0(""),

Str1(""),

Str2(""),

Str3(""),

Str4(""),

String1("");

 

#BeginCmtryOrAlert

if CommentaryEnabled and AtCommentaryBar then begin

 

if TradeOff = TRUE then Str0 = "TRUE" else

Str0 = "FALSE";

 

String1 =

newline +

newline + " TimedTrades_Sys " +

newline +

newline + " Date = " + NumToStr(Date, 0) +

newline + " Time = " + NumToStr(Time, 0) +

newline + " Open = " + NumToStr(Open, 4) +

newline + " Close = " + NumToStr(Close, 4) +

newline + " High = " + NumToStr(High, 4) +

newline + " Low = " + NumToStr(Low, 4) +

newline +

newline + " MP = " + NumToStr(MP, 0) +

newline + " TradeOff = " + Str0 +

newline + " StopTime = " + NumToStr(StopTime, 0) +

newline + " StartAgainTime = " + NumToStr(StartAgainTime, 0) +

newline + " LoseTrades = " + NumToStr(LoseTrades, 2) +

newline + " WinTrades = " + NumToStr(WinTrades, 2) +

newline + " WCount = " + NumToStr(WCount, 2) +

newline + " LCount = " + NumToStr(LCount, 2) +

newline +

newline;

Commentary(String1);

end;

#end;

end;// comm end

TIMEDTRADES.ELD

Share this post


Link to post
Share on other sites

You are very welcome. I received a lot of help from a lot of people over the years and very honestly continue to receive help. This is one of the toughest professions in the world and at very least it could become just a little easier if we help one another. Feel free to ask anytime.

 

Regards, Randall

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Topics

  • Posts

    • USDJPY PRICE OUTFLOW IS DRAWN BY SELLERS BACK TO 114.840   USDJPY Price Analysis – November 25 USDJPY price outflow is being held back as a consequence of bears causing opposition to the market influence. The price structure of the market strives to maintain an uptrend configuration under a bullish influence. However, the sellers are causing some resistance in the market, which is causing a hold in the market configuration. Because of this conflict in the market, the outflow of the bulls in the market will be held back to the 114.840 critical level. USDJPY Critical Levels Resistance Levels: 114.840, 112.790 Support Levels: 110.800, 109.100 USDJPY Long Term Trend: Bullish The bullish outflow price structure initially began with the expansive breadth of consolidation. The market was birthed after a strong price expansion before the bullish uprise. The price undulated between the breadth of the 110.800 and 109.100 significant price levels. As a result of this accumulation, the price was then pushed out to higher levels. With the continuation of the market expansion, buyers outflow upward, with the bulls taking hold of the market. Furthermore, price continues to experience more outflows as several structural levels were broken. When USDJPY eventually gets to the 112.790 level, the price resumes its accumulation phase. The market encountered a short phase of expansion before resuming bullish persistence. The price finally breaks through the 114.840 significant level and we expect a withdrawal back to this price level before bullish engagement. The Tensile Strength indicator shows the resilience of the market influence as the market is set to resume its bullish leverage after sellers retreat. USDJPY Short Term Trend: Bearish The 4-hour chart of USDJPY shows the price configuration riding upward following a strong force that broke through the 114.840 critical level. The price is now set in a retreat motion as the price is seen to be pulling away to the 114.840 price level. The Moving Average Convergence and Divergence indicator shows the market’s prevalent direction as the price is set on a pullback course to the 114.840 critical level before bullish outflow.   Source: https://learn2.trade
    • EURJPY DEPRECIATES TO LOWS NEAR 128.00 FOLLOWING COVID RESURGENCE   EURJPY Price Analysis – November 26 EURJPY pair fell for the third session in a row on Friday, depreciating to the area of recent lows in the 128.00 range. As the new strain of COVID weighs heavily on investors’ sentiment, strong buying interest in the Japanese yen puts EURJPY under added pressure in the sub-129.00 levels. Key Levels Resistance Levels: 130.50, 130.00, 129.61 Support Levels: 127.00, 126.50, 126.00 EURJPY Long term Trend: Ranging On Friday, the EURJPY opened higher at 129.31 and moved lower to 127.79 intraday lows losing almost 1%. The pair plunged, as bears emerged and traders focused on levels below 128.00. To investigate the bearish scenario, a decisive fall below 128.00 must be established. The pair may continue to fall into the next session, with bearish traders targeting the 127.00 area as a possible objective. As long as the 128.00 support level holds and the price is sustained above, more gains may be expected. A strong breakout of 128.50, on the other hand, would confirm that the rebound from 127.79 low has come to stay, bringing this low back into focus as a new bottom. EURJPY Short term Trend: Bearish The EURJPY is still trading bearishly from its October high of 133.47 on the 4-hour charts, and the intraday bias is still to the downside. If the resistance at 128.50 holds, a further drop is likely. A decisive rebound past 128.50, on the other hand, will consolidate on the entire rebound from 127.79 low level. The mid-term support turned resistance level of 130.00 will be the next level of contention. A break of revised support around the 128.00, on the other hand, might reverse the rebound and broaden the down leg from 130.00 with a new phase of the drop towards the mid 127.00 in the coming session.   Source: https://learn2.trade
    • Date : 25th November 2021. Market Update – November 25 – Solid US data lifts USD, Stocks, & Yields. USD (USDIndex 96.70) holds on at 16-mth highs; Strong set of US data yesterday GDP (2.1%) up a tick but missed by a tick, Claims (199k) at 52-yr low, PCE (0.4% m/m & 4.1% y/y), in-line & largest since Jan.1991, along with a big beat (5.9%) for GDP Price index, Durable Goods (0.5%) in-line, Personal Spending (1.3%) a big beat, Personal Income (0.5%) a beat, Trade balance a big beat (14.6%) on strong Exports, Inventories (-2.2%) a big miss, but shows demand is strong. Consumer Sentiment a beat and New Home Sales flat (745K) and missed. Stocks & Yields pushed higher, Oil held onto gains and Gold tested 3-week lows.   The FOMC Minutes showed (1) there could be a faster taper than the $15bn/mth currently planned, (2) Inflation could indeed be “persistent” (3) Clear division over 2022/23 rate hike cycle, Doves hold sway for now. US Yields 10yr trades at 1.644%, down from yesterday’s 1.694% high. Equities – Gains into the Holiday USA500 +10.76 (0.23%) at 4701 – USA500.F trades higher at 4713. USOil – peaked at $78.53 Inventories +1.0 vs -1.7 weakened prices – now at $77.65 Gold found a floor at 1782, but struggles to recoup $1800 at $1790. FX markets – EURUSD now 1.1216, having broken 1.1200, USDJPY now 115.36, from 115.50 & Cable back to 1.3350 from 1.3315 yesterday. Overnight – JPY PPI (1.0%) hit a 10-yr high, German GDP and consumer confidence both missed (1.7% vs 1.8% and -1.6% vs -1.0%) respectively. European Open – December 10-yr Bund future up 16 ticks, while US futures are slightly in the red. Bunds already outperformed yesterday, as EZ spreads widened in the wake of hawkish leaning ECB comments & confirmation that German finance ministry will go to the liberal FDP, which likely means more resistance to debt mutualisation across the EZ & more pressure on ECB to limit asset purchases. DAX & FTSE 100 futures are currently up 0.4% & 0.3% respectively & US futures are posting gains of 0.3-0.4%, suggesting markets are coping quite well with the prospect of less accommodative policies. Indeed, it seems to an extent that they welcome the CB’s acknowledgement that inflation risks could be less temporary than previously thought. Today – ECB Minutes, ECB’s Elderson, Schnabel, Lagarde and BOE’s Bailey Biggest FX Mover @ (07:30 GMT) CADJPY (0.20%) The rally from Tuesday’s low under 90.00 has been sustained with 91.25 being tested earlier today. MAs aligned higher, MACD signal line & histogram rising & over 0 line, RSI 61, H1 ATR 0.077, Daily ATR 0.707. Always trade with strict risk management. Your capital is the single most important aspect of your trading business. Please note that times displayed based on local time zone and are from time of writing this report. Click HERE to access the full HotForex Economic calendar. Want to learn to trade and analyse the markets? Join our webinars and get analysis and trading ideas combined with better understanding on how markets work. Click HERE to register for FREE! Click HERE to READ more Market news. Stuart Cowell Head Market Analyst HotForex Disclaimer: This material is provided as a general marketing communication for information purposes only and does not constitute an independent investment research. Nothing in this communication contains, or should be considered as containing, an investment advice or an investment recommendation or a solicitation for the purpose of buying or selling of any financial instrument. All information provided is gathered from reputable sources and any information containing an indication of past performance is not a guarantee or reliable indicator of future performance. Users acknowledge that any investment in FX and CFDs products is characterized by a certain degree of uncertainty and that any investment of this nature involves a high level of risk for which the users are solely responsible and liable. We assume no liability for any loss arising from any investment made based on the information provided in this communication. This communication must not be reproduced or further distributed without our prior written permission.
    • Date : 24th November 2021. Market Update – November 24 – USD & Yields Higher, Stocks Mixed, Oil Recovers. Trading Leveraged Products is risky USD (USDIndex 96.50) holds on at highs; EM currencies under particular pressure. (TRY lost 15% after Erdogan refused a rate rise). RBNZ raised rates but NZD fell (like the last time they raised rates!) JPY Inflation 2 ticks better than expected. USDJPY at January 2017 levels around 115.00. PMI data better across the globe, Stocks mixed in US & Asia, Yields bid, Oil recovered significantly and Gold pressured by yields. Biden invites Taiwan to its “Summit for Democracy”, WHO talks of additional 700k Covid deaths across Europe (Slovakia latest to talk lockdowns). US Yields 10yr trades at 1.667%, down from yesterday’s 1.684% high. Equities Mixed. Musk sold more stock, Banks & Oil majors lead. USA500 +7.76 (0.17%) at 4690 – USA500.F trades lower at 4684. USOil – rallied over 3% to $78.20 highs despite global strategic reserves being sold to cool prices. Gold found a floor at 1782, but struggles to recoup $1800 at $1790. FX markets – EURUSD down to 1.1245, USDJPY over 115.23, earlier now at 114.88 & Cable back to 1.3375. European Open – December 10-yr Bund future up 26 ticks, US futures also broadly higher. RBNZ delivered expected rate hike & markets seem to be scaling back fears of escalating inflation as even dovish leaning BoE & ECB members highlight risk of second round effects. ECB VP Guindos highlighted overnight that the drivers of inflation are becoming more structural, which adds to signals that the CB is finally ready to start reining in stimulus. DAX & FTSE 100 futures currently up 0.3% & 0.2% respectively. Today – Big data day ahead of Thanksgiving Weekend. – German Ifo, US Weekly Claims GDP, PCE, Durables, FOMC Mins. & ECB speak Biggest FX Mover @ (07:30 GMT) NZDJPY (-0.77%) RBNZ in-line but Dovish, sank from breach of 80.00 yesterday to 79.24, and 79.40 now. Faster MAs aligned lower, MACD signal line & histogram falling & below 0 line, RSI 35 & weak, Stochs OS. H1 ATR 0.17, Daily ATR 0.70. Please note that times displayed based on local time zone and are from time of writing this report. Click HERE to access the full HotForex Economic calendar. Want to learn to trade and analyse the markets? Join our webinars and get analysis and trading ideas combined with better understanding on how markets work. Click HERE to register for FREE! Click HERE to READ more Market news. Stuart Cowell Head Market Analyst HotForex Disclaimer: This material is provided as a general marketing communication for information purposes only and does not constitute an independent investment research. Nothing in this communication contains, or should be considered as containing, an investment advice or an investment recommendation or a solicitation for the purpose of buying or selling of any financial instrument. All information provided is gathered from reputable sources and any information containing an indication of past performance is not a guarantee or reliable indicator of future performance. Users acknowledge that any investment in FX and CFDs products is characterized by a certain degree of uncertainty and that any investment of this nature involves a high level of risk for which the users are solely responsible and liable. We assume no liability for any loss arising from any investment made based on the information provided in this communication. This communication must not be reproduced or further distributed without our prior written permission.
    • EURUSD HOVERS NEAR MULTI-MONTH LOW, UNDER 1.1250 LEVEL   EURUSD Price Analysis – November 24 Throughout the session, the EURUSD pair remained on the losing side and was last seen moving with considerable losses around the 1.1250-36 level. The announcement that the White House has opted to reappoint incumbent Fed Chair Jerome Powell for a second term sparked the recent strong dip. The spot is trading at 1.1253 at the time of writing, down 0.25 percent on the day. Key Levels Resistance Levels: 1.1525, 1.1422, 1.1300 Support Levels: 1.1200, 1. 1150, 1.1100 EURUSD Long term Trend: Bearish EURUSD has sunk to fresh multi-day lows, as seen on the daily chart, after extending the recent breach beneath the moving averages 5 around the 1.1300 level. This exposes the possibility of a deeper pullback and a re-test of the psychological support around 1.1200. Under the 1.1200 level, the euro’s underlying bullish attitude is in jeopardy. Overall, the EURUSD stays bearish while trading under the major horizontal support turned resistance and significant level at 1.1422. A breakout of the 1.1300 level, on the other hand, would aim for the 1.1350 level on the way to the 1.1400 zones. The fall of the 1.1200 zones, in the alternative scenario, is viewed as a bearish continuation indicator. EURUSD Short term Trend: Bearish The risk is weighted to the negative on the 4-hour chart, as the pair is developing below the firmly bearish 5 and 13 moving averages. Technical indicators have shifted to the downside, with negative levels. However, in the present scenario, the RSI has not yet reached oversold territory, allowing for more selling. On the upside, a break over the modest resistance level of 1.1300 might shift the intraday bias to neutral. On the downside, the 1.1200 zones provide initial support. The next important level of support is around the 1.1150 mark. If there are any more losses, the 1.1100 extension level of the low decline may be tested. Source: https://learn2.trade 
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.