NexusFi: Find Your Edge


Home Menu

 





IOG one entry per signal


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one kagein with 4 posts (1 thanks)
    2. looks_two ABCTG with 4 posts (2 thanks)
    3. looks_3 cowbearcar with 2 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 2,992 views
    2. thumb_up 3 thanks given
    3. group 3 followers
    1. forum 10 posts
    2. attach_file 0 attachments




 
Search this Thread

IOG one entry per signal

  #1 (permalink)
kagein
London
 
Posts: 4 since May 2013
Thanks Given: 2
Thanks Received: 1

I'm very new to EasyLanguage, this is my first ever attempt at programming but I'm stuck.

I'm trying to get a counter working so i only enter the market once per signal, not with every tick, when IOG is switched on. I've tried adding a counter function to long trades but I'm still having multiple entries. Could any of you tell me where I'm going wrong? Thanks


 
Code
[IntrabarOrderGeneration = True];

Inputs:
	Lots(1),
	ProfitTarget(1),
	StopLoss(6),	
	FastMovingAverage(50),
	SlowMovingAverage(100),
	RSIperiod(5),
	RsiOverbought(70),
	RsiOversold(30),
	HighestLowestRange(5),
	Orderdistance(5);
	
	
	
		

Vars:
	Ticsize(MinMove / PriceScale),
	fastavg(0),
	slowavg(0),
	myRSI(0),
	LimitPrice(0),
	TargetPrice(0),
	StopPrice(0),
	LongEntry(false),
	ShortEntry(false), 
	MP(0), // Marketposition
	intrabarpersist Count(0);
		
// Moving average and RSI variables
	
fastavg = Average(close,FastMovingAverage);
slowavg = Average(close,SlowMovingAverage);
myRSI = RSI(close,RSIperiod);
MP = marketposition(0);
count = 0;



// Long condition

If fastavg > slowavg and myRSI < RsiOversold and MP <> -1  then // also checks not short market
begin
	LongEntry = True ;
	end
else
	LongEntry = False;
	
	
// Short condition
If fastavg < slowavg and myRSI > RsiOverbought and MP <> 1  then // checks pnot long market
begin
	ShortEntry = True ;
	
	end
else
	ShortEntry = False;
	
	
	

//---------------------------------------------------Position Management---------------------------------------------//

//Long Entry


If LongEntry = True and count < 2 then		// Records limit, profit, and stop prices and places an order
begin
		LimitPrice = Lowest(low,HighestLowestRange);
		TargetPrice = LimitPrice + (ProfitTarget * Ticsize);
		StopPrice = LimitPrice - (StopLoss * Ticsize);
		Buy("entryL") lots contracts next bar at LimitPrice limit;	
		count = count + 1;	
end;


// Short entry 

If ShortEntry = True then
begin
		LimitPrice = Highest(high,HighestLowestRange);
		TargetPrice = LimitPrice -(ProfitTarget * Ticsize);
		StopPrice = LimitPrice + (StopLoss * Ticsize);
		Sellshort("entryS") lots contracts next bar at LimitPrice limit;
			
end;



// Stop Loss and Profit Target

If MarketPosition <> 0 then
begin
	setprofittarget_pt(Profittarget);
	setstoploss_pt(StopLoss);
		
end;

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
MC PL editor upgrade
MultiCharts
Exit Strategy
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
HumbleTraders next chapter
11 thanks
GFIs1 1 DAX trade per day journal
11 thanks
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627


kagein,

I would suggest that you take a look at the reserved word print. This allows you to print internal study values to the output / print log and can help you tremendously in finding out what is going on within your code.

In your case I'd check the value that count holds at the beginning, before you increment it and maybe at the end of the code.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #4 (permalink)
cowbearcar
Hong Kong, China
 
Posts: 14 since Apr 2017
Thanks Given: 0
Thanks Received: 1

Very nice and comprehensive coding.

First, You give 1 contracts on trade per Execute on signal,
but you allow more than 1 contracts on Property,
thus, IOG on will give more trade within Same bar.

RightClick -> Format Signal -> Properties... -> Position limit (Uncheck) Allow add to 10 entry orders in the same xxx


Besides, for coding, you add additional Checking:

if XXX and barssinceentry > 1 then to avoid extra entry within the same bar


Reply With Quote
  #5 (permalink)
cowbearcar
Hong Kong, China
 
Posts: 14 since Apr 2017
Thanks Given: 0
Thanks Received: 1

Oh Sorry, as you use limit order, it is NOT yet execute and throw the entry out IOG.

barssinceentry > 1 fail to skip extra orders.

New variable to carry BarNumber and NOT to throw order again within the same bar:

variable: LastOrderBarNumber(0);


If LongEntry = True and count < 2 and LastOrderBarNumber <> BarNumber then // Records limit, profit, and stop prices and places an order
begin
LimitPrice = Lowest(low,HighestLowestRange);
TargetPrice = LimitPrice + (ProfitTarget * Ticsize);
StopPrice = LimitPrice - (StopLoss * Ticsize);
Buy("entryL") lots contracts next bar at LimitPrice limit;
count = count + 1;
LastOrderBarNumber = BarNumber;
end;

=============================================================

barssinceentry > 1 only work if you give NEXT bar at market, but fail on limit orders

Reply With Quote
  #6 (permalink)
kagein
London
 
Posts: 4 since May 2013
Thanks Given: 2
Thanks Received: 1

Thanks a lot, i think i understand a bit better now.

On another note, I'm trying to manage a position once i've been filled. So essentially i want to move my profit target if three bars have passed since I've been in the trade. This is the code I've come up with, it doesn't seem to be doing the what i expect. IOG is false.

 
Code
//short


if marketposition = -1 then begin
	barnum = BarNumber;
	condit1 = (currentbar - barnum)=0;	//cuurentbar = entrybar
	condit2 = (currentbar - barnum)=3; // 3 bars away from  entry
	
	If condit1 = true then begin
	
		setstoploss_pt(stoploss);
		setprofittarget_pt(profittarget);
	end;
	
	If condit2 = true then begin
	
	setstoploss_pt(stoploss);
	setprofittarget_pt(0);
	end;
	
end;

Could you point to my mistake?

Reply With Quote
  #7 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

kagein,

what does the code do and what did you expect it do? This would help to know to point you in the right direction.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #8 (permalink)
kagein
London
 
Posts: 4 since May 2013
Thanks Given: 2
Thanks Received: 1

so what its meant to do is, when a limit order is filled it places a stop and a profit target. Three bars after entry, it then should move the profit target to entry(to scratch the trade). Leaving the stop where it is.

What it actually does is the first part, it just places the stop and profit target once the position is opened. The second part of the code doesn't do anything.

Reply With Quote
  #9 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

kagein,

check what values "currentbar" and "barnum" actually hold. The print reserved word could be helpful here, too.

On a separate matter the build in stop/target related reserved words should not be placed within conditional statements as this can impact their behavior.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #10 (permalink)
kagein
London
 
Posts: 4 since May 2013
Thanks Given: 2
Thanks Received: 1


Ok, using the print value i saw that my variable barnum always = 0. so i used the function barssinceentry and everything seems to work.

Reply With Quote
Thanked by:




Last Updated on July 4, 2017


© 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