Sell if closing pri...
 
Notifications
Clear all

[Solved] Sell if closing price is at least 5% lower from the buying point.

7 Posts
4 Users
5 Likes
750 Views
joeffrenz
(@joeffrenz)
Posts: 7
Active Member User
Topic starter
 

Hi VAI,

I'm having a problem with my sell condition. I want to sell if the closing price is at least 5% lower from my buying point. Here's the scenario. 

I bought at the closing price of 1.24 then the next day it closed at 0.97. So that's -21% from my buying point.

 

Here's my selling condition.

Set SellCondition = 100 - (100*(close/Buy)) > 4

100 - (100*(0.97/1.24)) = 21.7741935484

But it ignores my condition. Any help? See the attached image for your reference.

1618887807-STTF-Bug.png
 
Posted : 20/04/2021 11:03 am
snoperg
(@snoperg)
Posts: 15
Admin Admin
 

Use blockref to store the close price when your buy condition hit.

//Store the Buy Amount -> Blockref(value if condition1=True,value if condition2=True, Condition1, Condition2)
//If BuyCondition is true, buyAmt will keep the close price as buy amount. When SellCondition is True, buyAmt will be 0

set buyAmt= blockref(close,0,BuyCondition ,SellCondition)
set gain=if(buyAmt<>0, (close - buyAmt)/close,0)
set cutloss = buyAmt<>0 And gain < -0.05

 
Posted : 20/04/2021 12:00 pm
georgejr and joeffrenz reacted
joeffrenz
(@joeffrenz)
Posts: 7
Active Member User
Topic starter
 

@snoperg

Works like magic. Thanks!

 
Posted : 20/04/2021 2:42 pm
snoperg reacted
georgejr
(@georgejr)
Posts: 5
Active Member User
 

Hi VAI Users,

Not sure if my issue is related to this question, I have a different buy and sell condition; when I run it, there are more sell executed than buy.

How do I add the condition where I will only sell if there is currently a buy position and crossover (MA50, EMA20)?

Set BuyCondition = crossover(EMA20, MA50) AND (MACD_Line > MACD_Signal)
Set SellCondition = crossover(MA50,EMA20)
 
Posted : 28/04/2021 4:16 am
joeffrenz
(@joeffrenz)
Posts: 7
Active Member User
Topic starter
 

Hi @georgejr

Comment plot(buy,buy,green,main) and plot(sell,sell,red,main). Then use plotbuysell() function.

For Example:

//Comment 
//plot(buy,buy,green,main)
//plot(sell,sell,red,main)

//Use

plotbuysell(Buy,Sell,green,red,main)

 
Posted : 28/04/2021 7:56 am
georgejr reacted
Mike
 Mike
(@vanguardai)
Posts: 70
Co-Founder Admin
 

Just adding to @joeffrenz 

plot(buy,buy,green,main) and plot(sell,sell,red,main) will plot all the buy and sell signals, while plotbuysell(buy,sell,green,red,main) will only plot pairs of buy and sell signals.

 
Posted : 28/04/2021 10:04 am
georgejr reacted
georgejr
(@georgejr)
Posts: 5
Active Member User
 

@joeffrenz @vanguardai

Thank you mga sir. More power! 

 
Posted : 30/04/2021 9:34 am
Share: