Stop and profit/loss targets

Posted By: jpslvie

Stop and profit/loss targets - 02/14/21 11:44

Hey guys.

My name is João, I'm from Portugal and I have an academic background in economics, finance and financial markets. Started using Zorro to backtest some momentum strategies, but I really have no knowledge in C.

I have a very basic question: how would I define a stop loss of -5% from the initial open/entry/trade price? Apologies for the very basic question.

Anyway, thanks in advance and congrats for the Zorro project. It's a great edge to have.

Cheers!
Posted By: jpslvie

Re: Stop and profit/loss targets - 02/15/21 09:19

Ok, I think this is it (pretty basic, I know...):

Stop = 0.05 * priceClose();

I have another question, how do I exit a trade if price is higher than Keltner (C, 20, 3)?

Thank you!
Posted By: jpslvie

Re: Stop and profit/loss targets - 02/16/21 01:16

Why doesn't this work?

var Band = 3 * ATRS(20);
var SMATP = SMA(priceClose, 20);

TakeProfit = SMATP + Band;

(I get: Error 010: Invalid SPY TakeProfit: -0.0000)

Posted By: strimp099

Re: Stop and profit/loss targets - 02/17/21 13:46

priceClose() is a function and needs parentheses and the first arg to SMA is of type series. Example from the manual

Code

function run()
{
  vars Price = series(priceClose());
  vars SMA100 = series(SMA(Price,100));
  vars SMA30 = series(SMA(Price,30));
 
  if(crossOver(SMA30,SMA100))
    enterLong();
  else if(crossUnder(SMA30,SMA100))
    enterShort();
}

Posted By: jpslvie

Re: Stop and profit/loss targets - 02/21/21 20:50

Thank you!
Posted By: jpslvie

Re: Stop and profit/loss targets - 02/22/21 19:08

(removed)
© 2024 lite-C Forums