Forum

Algorithmic trading, quantitative analysis and Zorro Trader.

Please ask all Zorro Trader questions in the Zorro Trader forum. You need to sign up first.

Please or Register to create posts and topics.

Buy stop and buy limit

Hi,

I'm coming from easylanguage background.

I'm still finding and curious how yo buy stop or buy limit or sell stop or sell limit in zorro.

Example:

Buy next bar at highD(1) stop

Sellshort  next bar at LowD(1) stop

*With this 2 lines i can understand the market characteristic. It's more trending or sideway or prone to buy only or sell only.

Buy next bar at LowD(1) limit

Sellshort next bar at HighD(1) limit

* This is to understand whether the market is prone to mean reversion or not.

 

Based on example above. How is it being done in lite-C ?

 

Thanks.

 

 

Hello Hangtuah, and welcome to the forum!

Unfortunately, I have no background whatsoever in easylanguage, so I do not really understand the code you posted. However, I am willing to help. Please describe the strategy you want to trade or back-test in plain English, and I will gladly write the Lite-C code for you.

Meanwhile, you may want to take a look at the following resources:

Entering a trade (long or short): https://zorro-project.com/manual/en/buylong.htm

Trade Management Functions: https://zorro-project.com/manual/en/trade.htm

TMFs are one of the features where Zorro Trader really shines compared to other platforms!

Hi Algo Mike,

Thanks for the reply.

 

The logic as below:

Buy stop previous 1 day at high

Sell stop at previous 1 day at low.

 

Any of the direction hits, it will stop loss at high or low of previous 1 day and start to reverse to go to that direction.

 

1 more question. When you are going to have full algo trading course for zorro trader and combine it with R ?

Hi Hangtuah,

Unfortunately, I still don't understand the trading logic. However, I will try to implement here what I think you want to do. In plain English: enter a long trade when the price gets higher than the high of yesterday, enter a short trade when the price gets lower than the low of yesterday, and have a stop loss at the corresponding high and low. The Lite-C code is very simple:

function run()
{
BarPeriod = 1440;
MaxLong = MaxShort = 1; // we only want to be in one trade at a time

if(price(0) > priceHigh(1)) enterLong(Stop = priceHigh(1));
if (price(0) < priceLow(1)) enterShort(Stop = priceLow(1));
}

As you can see, if you want different stop losses for different trades, you pass the stop loss as an argument to the enterLong() or enterShort() functions. In Zorro Trader, price(0) is the price today, price(1) is the price yesterday etc.

If you wanted a "global" stop loss, this will do the trick:

function run()
{
BarPeriod = 1440;
MaxLong = MaxShort = 1; // we only want to be in one trade at a time

Stop = 0.01 * priceClose(); // we are taking a 1% risk

if(price(0) > priceHigh(1)) enterLong();
if (price(0) < priceLow(1)) enterShort();
}

Please note that the Stop passed as an argument overrides the global stop loss. Unfortunately, this is a terrible strategy, which only means that I really didn't understand what you wanted. Here's the performance on AAPL:

Annual return -38%
Profit factor 0.74 (PRR 0.50)
Sharpe ratio -0.64 (Sortino -0.69)

As for your last question, we're working on it! Meanwhile, here's an introduction: Trading with Neural Networks in Zorro Trader - YouTube

Hope this helps, and let me know if you have any other questions!

Uploaded files:
  • hangtuah_AAPL_1.png

@hangtuah

Hi! Did you have any luck with Algo Mike's code?