NexusFi: Find Your Edge


Home Menu

 





Max 2 trades, 1 if win, 2 if loss


Discussion in EasyLanguage Programming

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




 
Search this Thread

Max 2 trades, 1 if win, 2 if loss

  #1 (permalink)
thinkorn00b
stavanger
 
Posts: 19 since Sep 2020
Thanks Given: 1
Thanks Received: 1

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 NexusFi?
Better Renko Gaps
The Elite Circle
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Exit Strategy
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
ZombieSqueeze
Platforms and Indicators
 
  #2 (permalink)
 
syswizard's Avatar
 syswizard 
Philadelphia PA
 
Experience: Advanced
Platform: Multicharts
Broker: Ironbeam, Rithmic
Trading: Emini ES / NQ / CL / RTY / YM / BTC
Posts: 344 since Jan 2019
Thanks Given: 20
Thanks Received: 146

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

Reply With Quote
  #3 (permalink)
thinkorn00b
stavanger
 
Posts: 19 since Sep 2020
Thanks Given: 1
Thanks Received: 1


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
  #4 (permalink)
gary88888888
Changsha, China
 
Posts: 3 since Sep 2018
Thanks Given: 0
Thanks Received: 1

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
  #5 (permalink)
thinkorn00b
stavanger
 
Posts: 19 since Sep 2020
Thanks Given: 1
Thanks Received: 1

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
Thanked by:




Last Updated on October 9, 2022


© 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