">" and "="

MLlalala

Member
Here is a code :

case long:
if (price > trail[1]) {
state = state.long;
trail = Max(trail[1], malow);
} else {
state = state.short;
trail = mahigh;

I wanna state price>=trail[1], but if i add "=" after ">", it gives me error msg, so may i know how to do it
 
Solution
l1iG1UX.png

seems like its working
it says "invalid statement" after i inserted "=" after ">"
def state = {default init, long, short};
def trail;
switch (state[1]) {
case init:
if (!IsNaN(price)) {
switch (firstTrade) {
case long:
state = state.long;
trail = malow ;
case short:
state = state.short;
trail = mahigh;
}
} else {
state = state.init;
trail = Double.NaN;
}
case long:
if (price > trail[1]) {
state = state.long;
trail = Max(trail[1], malow);
} else {
state = state.short;
trail = mahigh;
}
case short:
if (price < trail[1]) {
state = state.short;
trail = Min(trail[1], mahigh);
} else {
state = state.long;
trail = malow;
}
}

plot TrailingStop = trail;
 
That is missing a lot of variable definitions, and other issues. Post the complete code if you have it. Otherwise, describe what you're trying to do in plain English. It would probably just be easier for me to write it from scratch.
 
That is missing a lot of variable definitions, and other issues. Post the complete code if you have it. Otherwise, describe what you're trying to do in plain English. It would probably just be easier for me to write it from scratch.
input length = 10;
input price = hl2;
input firstTrade = {default long, short};

def maHigh = highest(high, length);
def maLow = lowest(low, length);
#def bp = if maHigh < maHigh[1] then maHigh else bp[1];
#def sp = if maLow > maLow[1] then maLow else sp[1];


def state = {default init, long, short};
def trail;
switch (state[1]) {
case init:
if (!IsNaN(price)) {
switch (firstTrade) {
case long:
state = state.long;
trail = malow ;
case short:
state = state.short;
trail = mahigh;
}
} else {
state = state.init;
trail = Double.NaN;
}
case long:
if (price > trail[1]) {
state = state.long;
trail = Max(trail[1], malow);
} else {
state = state.short;
trail = mahigh;
}
case short:
if (price < trail[1]) {
state = state.short;
trail = Min(trail[1], mahigh);
} else {
state = state.long;
trail = malow;
}
}



plot TrailingStop = trail;

#plot BuyStop = if state == state.short or state != state[1] then trail else Double.NaN;


#plot SellStop = if state == state.long or state != state[1] then trail else Double.NaN;

TrailingStop.SetPaintingStrategy(PaintingStrategy.POINTS);
TrailingStop.DefineColor("Buy", GetColor(0));
TrailingStop.DefineColor("Sell", GetColor(1));
TrailingStop.AssignValueColor(if state == state.long
then TrailingStop.Color("Sell")
else TrailingStop.Color("Buy"));
 
This is the complete code, I "#" the unwanted statement which is redundant. Bsically it is like a high low activator in TOS, i wanna define if current close is greater or equal to the highest high of previous x bars. THis code originally only defined price is greater than previous highest high, now i just want to add "=", i believe other codes may not need to be changed
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
433 Online
Create Post

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