Max 2 trades, 1 if win, 2 if loss - futures io
futures io



Max 2 trades, 1 if win, 2 if loss


Discussion in EasyLanguage Programming

Updated
    1. trending_up 1,197 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 4 posts
    2. attach_file 1 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
 

Max 2 trades, 1 if win, 2 if loss

(login for full post details)
  #1 (permalink)
thinkorn00b
stavanger
 
 
Posts: 12 since Sep 2020
Thanks: 1 given, 1 received

Hi

I'm trying to prevent my code to re-short after it takes a win. If it takes a loss (stop out at high of day), I want it to re-short once more. So max 2 attempts each day.

The code now will re-short even if it takes a win, and it will re-short base on the criteria.

What I try to do, is to have a condition that says that if the grossloss>=0 (which means it haven't covered the position, OR it have taken a loss) and total number of entries are less or equal to 2 then it can short. This means that if the position is covered at 1 vwap deviation, which means a win, no more shorts should be taken, and if it didn't covered, and the stock made a new high, then it would take a loss, and make a new short when the other condition is met.


 
Code
										{ENTRY CODE}  
//Variables for Ashi sign top  
 Variables:    
               SynTopen ( 0 ), 
               SynTClose ( 0 ), 
               SynOpen( 0 ),    
               SynClose( 0 ),  
               Intrabarpersist bool Flag( False ),  
               VWAPIndic( 0 ), 
               DevDistCover( 0 ), 
               Intrabarpersist Stoplosspricechng (0), 
 			   proftargetpricechng (0), 
 			   extracentsrisk (0), 
 			   int MP(0), 
               DevDist( 0 ); 
                         
  
//if(Getappinfo(Airealtimecalc) = 1) then   
//begin  
//Ashi sign top code for variables: 
               SynOpen  = (SynOpen[1]+SynClose[1])*.5;    
               SynClose = (Open+High+Low+Close)*.25; 
                
               SynTOpen  = (Open[2]+Close[2])*.5;    
               SynTClose = (Open[1]+High[1]+Low[1]+Close[1])*.25;       
                
               VWAPIndic = VWAP_H;  
               DevDist = 0.1;  
          
                     
                              
               Condition1 =  (Ticks[0] > 200000);  
               if Condition1 then   
                              Flag = true;  
                 
               Condition2 = SynClose <= SynOpen;    
                              
               if Flag and Condition2 And (Entriestoday(date) <=	2) and (grossloss >=0) then 
               
               
Begin      
if t >= 0930 and t <= 1300 Then           
Sell short( !( "short" ) ) 100 shares next bar at market; 
 
end;              
                
             
                
         	  MP = Marketposition; 
         	   
       	 
         	  DevDistCover = 0.01; 
         	 
	 
	//The variable stoplosspricechng is set to the entryprice of the current short position minus the high of day 
	// this value is updated each tick of the bar 
	Stoplosspricechng =  ((highD(0)) - entryprice); 
	proftargetpricechng = Entryprice - openD(0); 
	 
 
begin 
setstopshare; 
If (Close 	<	 (VWAPIndic+(DevDistCover*-1)))then BuyToCover This Bar on Close; 
if MP <> 0 then setstoploss(stoplosspricechng); 
end; 
// Stop loss code (right above HOD)


However, as seen in the image above, it re-short right after a win, which it shouldn't

Reply With Quote

Can you help answer these questions
from other members on futures io?
Asking Wall Street Billionaire for Investment Advice
Psychology and Money Management
IKYP - How I solved email troubles on VPS
NinjaTrader
Reaching Customer Service
NinjaTrader
 
 
(login for full post details)
  #2 (permalink)
 syswizard 
Philadelphia PA
 
Experience: Advanced
Platform: Multicharts
Broker: Ironbeam, Rithmic
Trading: Emini ES / NQ / CL / RTY / YM / BTC
 
syswizard's Avatar
 
Posts: 342 since Jan 2019
Thanks: 20 given, 136 received

I think you need to re-state your rules more succinctly. The current version is pretty convoluted IMHO.

Reply With Quote
 
(login for full post details)
  #3 (permalink)
thinkorn00b
stavanger
 
 
Posts: 12 since Sep 2020
Thanks: 1 given, 1 received


okay, what would you recommend instead of using these two conditions to prevent the script to re-short after a win, and to re-short after a loss? (
 
Code
Entriestoday(date) <=	2) and (grossloss >=0)

Reply With Quote
 
(login for full post details)
  #4 (permalink)
gary88888888
Changsha, China
 
 
Posts: 3 since Sep 2018
Thanks: 0 given, 1 received

Your strategy is too complicated, I didn't take a closer look and it's not easy to change it.
You need to define two variables, one to track the number of failed trades and one to track the number of successful trades.
Stop trading if you lose twice and stop trading if you win once.

Reply With Quote
 
(login for full post details)
  #5 (permalink)
thinkorn00b
stavanger
 
 
Posts: 12 since Sep 2020
Thanks: 1 given, 1 received

I got it work the way I wanted intraday, only thing is that it stops after one day, I cant get it to reset each day.
 
Code
										{ENTRY CODE} 
//Variables for Ashi sign top 
 Variables:   
               SynTopen ( 0 ),
               SynTClose ( 0 ),
               SynOpen( 0 ),   
               SynClose( 0 ), 
               Intrabarpersist bool Flag( False ), 
               VWAPIndic( 0 ),
               DevDistCover( 0 ),
               Intrabarpersist Stoplosspricechng (0),
 			   proftargetpricechng (0),
 			   TradesCounter(0),
 			   TradesCounterWholeday (0),
 			   mp(0),
 		 	   DevDist( 0 );
                         
 
//if(Getappinfo(Airealtimecalc) = 1) then  
//begin 
//Ashi sign top code for variables:
               SynOpen  = (SynOpen[1]+SynClose[1])*.5;   
               SynClose = (Open+High+Low+Close)*.25;
               
               SynTOpen  = (Open[2]+Close[2])*.5;   
               SynTClose = (Open[1]+High[1]+Low[1]+Close[1])*.25;      
               
               VWAPIndic = VWAP_H; 
               DevDist = 0.0; 
         
               MP = Marketposition;  
                             
               Condition1 =  ((Ticks[0] > 200000) )); 
               if Condition1 then  
                              Flag = true; 
                
               Condition2 = (SynClose <= SynOpen);   
               
               if ( MP[1] <> MP ) then TradesCounterWholeday = TradesCounterWholeday+ 1;
               
               if ( MP <> 0 ) and (MP[1] <> MP ) then TradesCounter = TradesCounter+ 1;
               
               if TradesCounterWholeday <=	3 then Begin
                             
               if Flag and Condition2 and tradescounter 	< 1 then            
Begin     
if t >= 1532 and t <= 1700 Then          
Sell short( !( "short" ) ) 100 shares next bar at market;

end;             
               
            
               If ( (High[0] = HighD(0))) and grossprofit <=0 then TradesCounter = 0;
         	          	  
       	
         	  DevDistCover = 0.2;
         	
	

	//The variable stoplosspricechng is set to the entryprice of the current short position minus the high of day
	// this value is updated each tick of the bar
	Stoplosspricechng =  ((highD(0)) - entryprice);
	proftargetpricechng = Entryprice - openD(0);
	

begin
setstopshare;
If (Close 	<	 (VWAPIndic+(DevDistCover*-1)))then BuyToCover This Bar on Close;
if MP <> 0 then setstoploss(stoplosspricechng);
end;
// Stop loss code (right above HOD)


end;

Reply With Quote
The following user says Thank You to thinkorn00b for this post:


futures io Trading Community Platforms and Indicators EasyLanguage Programming > Max 2 trades, 1 if win, 2 if loss


Last Updated on October 9, 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