Skip to content

Instantly share code, notes, and snippets.

@iCodeForBananas
Created April 18, 2023 15:25
Show Gist options
  • Save iCodeForBananas/caae438f0da6165b26350c46cbee7a91 to your computer and use it in GitHub Desktop.
Save iCodeForBananas/caae438f0da6165b26350c46cbee7a91 to your computer and use it in GitHub Desktop.
Inputs:
TradeSize(1),
EmaLength(30),
StopSize(10);
Variables:
Ema(0),
PriorBarHigh(0),
PriorBarLow(0);
Ema = XAverage(Close, EmaLength);
If CrossesAbove(Close, Ema) Then
Begin
PriorBarLow = Low[1];
Buy ("Long") TradeSize Shares Next Bar at Market;
Sell ("LongStop") TradeSize Shares Next Bar at PriorBarLow - StopSize Stop;
End;
If CrossesBelow(Close, Ema) Then
Begin
PriorBarHigh = High[1];
SellShort ("Short") TradeSize Shares Next Bar at Market;
BuyToCover ("ShortStop") TradeSize Shares Next Bar at PriorBarHigh + StopSize Stop;
End;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment