Maximum of One Trade per Minute

Posted By: OptimusPrime

Maximum of One Trade per Minute - 08/17/21 21:00

Hi Team:

I am exploring various timing algorithms to use within a script. I can't figure out how to allow no more than one trade within a one-minute period. This one-minute rule is to apply, regardless of all other periodicity, trade direction, Timeframes, BarPeriods, etc. It's like a stand-alone timer that makes sure we never enter more than one trade within a minute.

Do you have any suggestions on how I might accomplish this?

Thanks so much
Posted By: Lapsa

Re: Maximum of One Trade per Minute - 08/17/21 21:20

It's possible to restrict total amount of trades per side.

Code
MaxLong = 5;
MaxShort = 5;


But that's not exactly the same as 1 per minute.

One approach might be to store the value of minute(0) and then check up that minute(0) != stored_minute if (NumOpenLong || NumOpenShort) > 0.
Posted By: Lapsa

Re: Maximum of One Trade per Minute - 08/17/21 21:59

It's sort of dumb approach.


Using hours as I lack tick data.

Code
#include <profile.c>

var storedHour = .0;

function run()
{
	set(PLOTNOW);
	BarPeriod = 1;
	LookBack = 100;
	StartDate = 20210715;
	EndDate = 20210816;

	var currentHour = hour(0);
        // var currentMinute = minute(0);
	
	bool goLong = random() > 0;
	bool goShort = !goLong;
			
	bool sureWhyNot =
		(NumOpenLong + NumOpenShort) <= 0 ||
		currentHour != storedHour;
	
	if (goLong && sureWhyNot) {
		enterLong();
		storedHour = currentHour;
	}		
	
	if (goShort && sureWhyNot) {
		enterShort();
		storedHour = currentHour;
	}
}


[Linked Image]


To be fair - I would question necessity for such feature.
Posted By: OptimusPrime

Re: Maximum of One Trade per Minute - 08/18/21 03:20

Hi Lapsa: Thanks for your response. I found minute() in the manual and I am testing it as follows. https://zorro-trader.com/manual/en/month.htm

if(minute() != StoredMinute)
TradeAllowed = true;

Appreciated !
© 2024 lite-C Forums