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

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
374 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top