Howdy,
Created a study for a forex automatic strategy on a 10M chart. Using 10EMA moving average. The intent is for once the price action crosses the 10EMA in the long position, take a trade. Stay in the trade until a certain percentage of gain (i.e. 4%), then exit the trade. However, the strategy does not take teh trade at all. The moving average does chart though.
input tradeSize = 10000;
input pricetype = PriceType.LAST;
input price = close;
input averageType = AverageType.EXPONENTIAL;
input length = 10;
input displace = 0;
input showBreakoutSignals = no;
input percentGainGoal = 4;
input percentLossGoal = -2;
input avgLength = 10; #Length of Moving Average
#DEFINE___________________
def MovingAvg = Average(averageType, avgLength);
def PerChange = (100 * (price - EntryPrice())) / EntryPrice();
def TradePrice = close(pricetype = pricetype);
#ORDERS___________________
def buySignal = TradePrice crosses above MovingAvg;
def exitGood = PerChange > percentGainGoal;
def exitBad = PerChange < percentLossGoal;
def market = price;
#SALES___________________
AddOrder(OrderType.BUY_TO_OPEN, buySignal, market[-1], tradeSize, Color.CYAN, Color.CYAN);
AddOrder(OrderType.SELL_TO_CLOSE, exitGood, market[-1], tradeSize, Color.GREEN, Color.GREEN);
#PLOTS___________________
plot movingAvgCrossover = Average(price, avgLength);
#ALERT___________________
Alert(buySignal, "RP_Price_Cross");
Created a study for a forex automatic strategy on a 10M chart. Using 10EMA moving average. The intent is for once the price action crosses the 10EMA in the long position, take a trade. Stay in the trade until a certain percentage of gain (i.e. 4%), then exit the trade. However, the strategy does not take teh trade at all. The moving average does chart though.
input tradeSize = 10000;
input pricetype = PriceType.LAST;
input price = close;
input averageType = AverageType.EXPONENTIAL;
input length = 10;
input displace = 0;
input showBreakoutSignals = no;
input percentGainGoal = 4;
input percentLossGoal = -2;
input avgLength = 10; #Length of Moving Average
#DEFINE___________________
def MovingAvg = Average(averageType, avgLength);
def PerChange = (100 * (price - EntryPrice())) / EntryPrice();
def TradePrice = close(pricetype = pricetype);
#ORDERS___________________
def buySignal = TradePrice crosses above MovingAvg;
def exitGood = PerChange > percentGainGoal;
def exitBad = PerChange < percentLossGoal;
def market = price;
#SALES___________________
AddOrder(OrderType.BUY_TO_OPEN, buySignal, market[-1], tradeSize, Color.CYAN, Color.CYAN);
AddOrder(OrderType.SELL_TO_CLOSE, exitGood, market[-1], tradeSize, Color.GREEN, Color.GREEN);
#PLOTS___________________
plot movingAvgCrossover = Average(price, avgLength);
#ALERT___________________
Alert(buySignal, "RP_Price_Cross");