How to stop trades in the same direction

Gradiusr

New member
VIP
i modified a BENTEN S
Moving Average Crossovers
TO simple strategy script to enter long when a 10 mov crosses above 400mov and the same for short trading //then i added a take profit to stop the trade .AND STOP ;OSS AS WELL .the annoying think is that after the take profit exit the script generates new signal in the same direction .i tried everything ,,without any success/any help??
 
Last edited by a moderator:
i created a simple strategy script to enter long when a 10 mov crosses above 400mov and the same for short trading //then i added a take profit to stop the trade .the annoying think is that after the take profit exit the script generates new signal in the same direction .i tried everything ,,without any success/any help??
how is anyone going to help modify your code, without your code ?
 
how is anyone going to help modify your code, without your code ?

Ruby:
input price = close;
input fastLength = 10;
input slowLength = 450;
input averageType = AverageType.SIMPLE;
input targetProfitPoints = 3;
input stopLossPoints = 1; # You can adjust this value as needed

plot FastMA = MovingAverage(averageType, price, fastLength);
plot SlowMA = MovingAverage(averageType, price, slowLength);
FastMA.SetDefaultColor(GetColor(1));
SlowMA.SetDefaultColor(GetColor(2));

plot ArrowUp = if FastMA - 2 crosses above SlowMA
then low - 10
else Double.NaN;
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp.SetLineWeight(3);
ArrowUp.SetDefaultColor(Color.GREEN);
plot ArrowDN = if FastMA + 2 crosses below SlowMA
then high + 10
else Double.NaN;
ArrowDN.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDN.SetLineWeight(3);
ArrowDN.SetDefaultColor(Color.RED);
Alert(ArrowUp, " ", Alert.BAR, Sound.Chimes);
Alert(ArrowDN, " ", Alert.BAR, Sound.Bell);

DefineGlobalColor("Bullish", Color.YELLOW);
DefineGlobalColor("Bearish", Color.RED);
input seeClouds = yes;
AddCloud(If(seeClouds, FastMA, Double.NaN), SlowMA, GlobalColor("Bullish"), GlobalColor("Bearish"));

# Generate exit conditions for both buy and sell
def exitConditionBuy = close > EntryPrice() + targetProfitPoints;
def exitConditionSell = close < EntryPrice() - targetProfitPoints;

# Generate stop-loss conditions for both buy and sell
def stopLossBuy = close < EntryPrice() - stopLossPoints;
def stopLossSell = close > EntryPrice() + stopLossPoints;

# Add buy and sell orders
AddOrder(OrderType.BUY_AUTO, FastMA - 2 crosses above SlowMA);
AddOrder(OrderType.SELL_AUTO, FastMA + 2 crosses below SlowMA);


# Close the buy position when the exit condition is met
AddOrder(OrderType.SELL_TO_CLOSE, exitConditionBuy, open[-1], 1, Color.WHITE, Color.WHITE);
# Close the sell position when the exit condition is met
AddOrder(OrderType.BUY_TO_CLOSE, exitConditionSell, open[-1], 1, Color.YELLOW, Color.YELLOW);
# Add stop-loss orders
AddOrder(OrderType.SELL_TO_CLOSE, stopLossBuy, open[-1], 1, Color.RED, Color.RED);
AddOrder(OrderType.BUY_TO_CLOSE, stopLossSell, open[-1], 1, Color.GREEN, Color.GREEN);

my mistake!!!
 
Last edited by a moderator:

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
410 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