• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

Forex Study - 10EMA

DoQtorNo

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");
 

DoQtorNo

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.
 

Pensar

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

37qI57Q.png


And once I remove/modify the exit conditions -

MIWwsLA.png


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

DoQtorNo

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.
 

Pensar

Well-known 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