NexusFi: Find Your Edge


Home Menu

 





not to enter a position if the previous position was closed in a stop loss


Discussion in EasyLanguage Programming

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




 
Search this Thread

not to enter a position if the previous position was closed in a stop loss

  #1 (permalink)
OMEGAA
milan italy
 
Posts: 10 since Nov 2022
Thanks Given: 0
Thanks Received: 0

Hello, I use EasyLanguage as my programming code with TradeStation. I'm having trouble telling the code not to enter a position if the previous position was closed in a stop loss. Does anyone have any suggestions? Thank you

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
Trade idea based off three indicators.
Traders Hideout
ZombieSqueeze
Platforms and Indicators
What broker to use for trading palladium futures
Commodities
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
  #2 (permalink)
 TraderDoc2 
Plainview
 
Experience: Intermediate
Platform: TradeStation
Broker: TradeStation
Trading: Futures
Posts: 34 since Mar 2012
Thanks Given: 1
Thanks Received: 21

It would help if you would provide a little more information about exactly what you want to do. Are you day-trading and want to experience no more than one losing trade per day?
Or do you have something else in mind? If you are day-trading, do you ever exit a trade at a loss before the end-of-session without being stopped out?

Follow me on Twitter Reply With Quote
  #3 (permalink)
 
AlgOz's Avatar
 AlgOz 
Sydney, Australia
 
Experience: Beginner
Platform: TradeStation, MultiCharts
Broker: TradeStation
Trading: Futures, stocks
Posts: 7 since Jun 2021
Thanks Given: 4
Thanks Received: 4


OMEGAA, have a look at the risk protection #2 on Kevin's website: https://kjtradingsystems.com/risk-protection-techniques.html.

it shows a simple approach to "wait a while after losing trade" and see if this is is what you are looking for. At tleast this may point you in the right direction.

Other good sources can be the tradestation forums (in case have not tried that already...) and the Easy Language Mastery Website: https://easylanguagemastery.com/. You can get good code scripts from both sites for free.

Hope that helps.

Reply With Quote
  #4 (permalink)
OMEGAA
milan italy
 
Posts: 10 since Nov 2022
Thanks Given: 0
Thanks Received: 0

As the first entry, I write the exact date. For example, if I'm conducting a 3-year backtest, I specify the day: If marketposition=0 and time=time_ and date=dateexactly, then buy next bar at market.

For the second entry to continue the strategy: If marketposition=0 and time=time_ and entryprice(1)<exitprice(1), then buy next bar at market.

The issue now is that I want to instruct the code that, by writing the first two lines, it should continue entering a position only if the previous position was profitable. It should stop after the first stop loss. I would like to add a condition to continue entering positions only if I achieve a take profit (TP). In this case, after the first stop loss, I would be back in a position, but I would start counting from the next one.

Reply With Quote
  #5 (permalink)
 TraderDoc2 
Plainview
 
Experience: Intermediate
Platform: TradeStation
Broker: TradeStation
Trading: Futures
Posts: 34 since Mar 2012
Thanks Given: 1
Thanks Received: 21

This might work or at least get you on the right track:

 
Code
{Test Strategy}

Input:
QuietBars(5),
MinBars(3),
MMStop(750);

Vars:
TotTr(0),
OK_To_Trade(True),
BarsToday(0);


If Time = SessionFirstBarTime(0,1) then begin
BarsToday = 1;
OK_To_Trade = True;
end
Else
BarsToday = BarsToday + 1;

If marketposition=0 and OK_To_Trade then buy("LE1") next bar at market;

If MarketPosition > 0 then Begin
If BarsSinceEntry >= MinBars and Close > Close[2] and Close > EntryPrice then Sell("LX1") next bar at market; {This is a Take Profit Condition as an example}
End;

TotTr = Totaltrades;
If TotTr > TotTr[1] then begin
If PositionProfit(1) < 0 then OK_To_Trade = False;
end;

If BarsToday >= 2 and BarsSinceExit(1) >= QuietBars then OK_To_Trade = True;

If Time = CalcTime(SessionEndTime(0,1),-BarInterval) then Sell next bar at market;

TotTr = Totaltrades;
If TotTr > TotTr[1] then begin
If PositionProfit(1) < 0 then OK_To_Trade = False;
end;

If PositionProfit(0) < 0 then OK_To_Trade = False;

//If Date = 1231016 and time = 0845 then print("MP = ",marketposition:0:0," BarsSinceExit = ",BarsSinceExit(1):0:0," TotTr = ",TotTr:0:0," TotTr[1] = ",TotTr[1]:0:0);


SetStopContract;
SetStoploss(MMStop);

Follow me on Twitter Reply With Quote
  #6 (permalink)
OMEGAA
milan italy
 
Posts: 10 since Nov 2022
Thanks Given: 0
Thanks Received: 0

Thank you for the help, it helped me a lot. If you need a hand with any code, feel free to reach me

Reply With Quote




Last Updated on October 19, 2023


© 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