Forex Study - 10EMA

D

DoQtorNo

New member
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");
 
MerryDay

MerryDay

Member
VIP
Did you save this as a "study" or as a "strategy"?
It needs to be saved under the strategy tab which is to the right of the study tab...
 
P

Pensar

Active member
VIP
@DoQtorNo Perhaps try changing this
Code:
 def MovingAvg = Average(averageType, avgLength);
to this?
Code:
def MovingAvg = MovingAverage(averageType, price, avgLength);
 
D

DoQtorNo

New member
Yes. I saved it under the Strategy tab. And I adjusted teh code to
def MovingAvg = MovingAverage(averageType, price, avgLength);

Trade still did not fire off once price action crossed the 10EMA.
 
P

Pensar

Active member
VIP
@DoQtorNo Here is a snip of the results once I changed the code, it places one buy order -



And once I remove/modify the exit conditions -



I would try re-thinking the exit conditions in the original code.
 
D

DoQtorNo

New member
Thanks. Is there a general setting on ToS that I need to ensure it's turned on (i.e. autotrade button to On versus Off)? I'm still learning my way around the platform so forgive the elementary question. But I'm running it against forex pairs and i'm watiching the price action cross the 10MA and it doesn't enter a trade at all.
 
P

Pensar

Active member
VIP
Thanks. Is there a general setting on ToS that I need to ensure it's turned on (i.e. autotrade button to On versus Off)? I'm still learning my way around the platform so forgive the elementary question. But I'm running it against forex pairs and i'm watiching the price action cross the 10MA and it doesn't enter a trade at all.
@DoQtorNo ThinkorSwim doesnt support autotrading. Strategies such as the one above are mainly used for backtesting of ideas, as any real-money trades placed have to be done manually.
 

Similar threads

Top