Qscript Exitlong

Have a QScript to share, or need help with programming? Post your comment here.
Post Reply
Loga18
Posts: 3
Joined: Tue Feb 18, 2025 11:14 pm
Contact:

Qscript Exitlong

Post by Loga18 » Fri Apr 11, 2025 3:56 pm

Hello everyone,

I start to use Qscript :) and I have a little problem with this code. Every long exit or short exit is on the same 1 minute bar of the entry, I have +1, -1 or -1, +1 on the same bar. I just want 10 points of profit or 10 points of stop loss for the system report.

Thanks a lot,

if (avg1 crosses over avg2) {
buy(1, close, "market", "day");
exitlong(0,entryprice+10,"market","day"); # Take profit
exitlong(0,entryprice-10,"stop","day"); # Stop loss
}

if (avg1 crosses under avg2) {
sell(1, close, "market", "day");
exitshort(0,entryprice+10,"market","day"); # Take profit
exitshort(0,entryprice-10,"stop","day"); # Stop loss
}

plot1 = avg1;
color1 = blue;
plot2 = avg2;
color2 = red;

sbank
Posts: 193
Joined: Tue Jul 21, 2015 9:35 pm
Contact:

Re: Qscript Exitlong

Post by sbank » Mon Apr 14, 2025 6:57 pm

There are probably a couple changes I would do. I would change the expiration to be "onebar" instead of "day". Also you are using a market order for the profit target. Probably should be a limit order. And lastly, I would wrap your exits around the value of marketposition.

See if the following code does what you want:

Code: Select all

if (avg1 crosses over avg2) {
   buy(1, close, "market", "day");
}
if (marketposition >= 1) {
   exitlong(0,entryprice+10,"limit","onebar"); # Take profit
   exitlong(0,entryprice-10,"stop","onebar"); # Stop loss
} 

Loga18
Posts: 3
Joined: Tue Feb 18, 2025 11:14 pm
Contact:

Re: Qscript Exitlong

Post by Loga18 » Tue Apr 15, 2025 7:38 pm

Hello,

Thanks a lot Sbank it s better :) .

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests