VitalySvyatyuk / pocket_option_trading_bot

Bot for autotrade in Pocket Option
26 stars 11 forks source link

Can you read indicator values #1

Closed x-ender closed 4 months ago

x-ender commented 5 months ago

Assuming I have a strategy that help me derive signals with the help of indicators.. and I want to automate it, can it be implemented. I mean, can you read indicator values in code and provide signals based on certain indicators values.

VitalySvyatyuk commented 5 months ago

Yes, indicators can be used. You can jump back to the commit 0834f5a7adf3d1082e285151b06a8a60b3b5fc38 where indicators are presented in the code. Any indicators and their combinations. What kind of strategy do you have? I can backtest it.

x-ender commented 5 months ago

Okay Great. Sorry I didn't reply on time. I've got a strategy that works about 85 to 90% of the time but its a 5min time game.

Indicators

Strategy So i understand that the parabolic SAR indicates a trend and it end when some candles going the opposite trend intersects it. And this can be seen indicated also by the histogram of the Awesome Oscillator. Now, at the point of intersection of the parabolic SAR, at the beginning of a new candle and immediately when the histogram indicates a movement from negative to positive or vice-versa, a call or put signal is created.

I have a screenshot of what i explained below. It works better on the 5mins chart and trade time.

Screenshot 2024-02-01 at 7 56 30 AM
VitalySvyatyuk commented 5 months ago

Thanks for the details and your strategy. I will check it soon, a week or two. For my current setup, it's easier to test < 1m timeframes, and it's because of data received from PO websocket. For everything > 1m the code should be updated. Btw, have you tried your strategy on different timeframes and symbols? Or only 5m and USDCNHOTC?

x-ender commented 5 months ago

Yes I have and found out it works best with the 5min timeframe on any market

x-ender commented 5 months ago

Thank you. I'm learning python now so i can understand your code properly.. lol.. I've tested the code btw and it works on my system well 👍 .

marmarart commented 5 months ago

Can you share with us code with your strategy?

x-ender commented 5 months ago

oh no.. I meant that i've tested his code. I'm still learning python. I understand about half his program

VitalySvyatyuk commented 5 months ago

Current results with such strategy for 5m/5m timeframe/time:

x-ender commented 5 months ago

Wow.. that is not so bad. Please will you be kind to share the code with me when you're done. It'll really be an upgrade for me trading. Also to learn.

VitalySvyatyuk commented 5 months ago

I added a new script po_bot_indicators.py. It works on 1m and 5m timeframes. 1m can be used to check strategy quickly. The important part is inside get_indicators(). For 1m chart, this function runs every minute, and for 5m chart, it runs every 5 minutes. You can update this function with your params, by changing fast_periods for example.

VitalySvyatyuk commented 5 months ago

Tested again this strategy, and now the result is not so high, it's even < 50%

x-ender commented 5 months ago

Okay. I'll study the code and python and see how I can implement other strategies as well. I appreciate your time and effort. Thank you

x-ender commented 5 months ago

Tested again this strategy, and now the result is not so high, it's even < 50%

I've tested it and noticed that the call or put action is initiated on the second candle after the Ao crossing. I guess that's why it's giving that poor accuracy.

VitalySvyatyuk commented 5 months ago

Maybe. You can try different AO and PSAR params to make them more synced.

x-ender commented 4 months ago

Okay

VitalySvyatyuk commented 4 months ago

What I found is OTC and non-OTC currencies work differently. It's almost impossible to predict OTC movement. It seems that they have some script that unpredictably changes the direction of OTC pairs. For me, the way to go is to use only non-OTC pairs whose movement is the same on all brokers. 85-91% is less than 92%, but here you can at least predict something.

x-ender commented 4 months ago

Yeah.. I think so too.

I'm currently trying to implement a new strategy using moving average crossover and fractal.

I've also tried to make the bot open and analyse multiple markets from a list of markets but to no avail.. I keep getting errors.

I'll share the new strategy

x-ender commented 4 months ago

So the strategy goes like this. It's very simple.

Indicators

Moving Average1 (Period: 3, SMA) Moving Average2 (Period: 7, SMA) Fractal (Period: 3)

Strategy When the MA1 crosses above the MA2, and the last indicator of the fractal is red, then a call signal action is called. When the MA1 crosses below the MA2, and the last indicator of the fractal is green, the a put signal action is called.

Note: Do not call any signal action if the two moving averages have met or are on the verge of meeting or about to cross. Signal action should be called in the beginning of the next candle when a cross has been confirmed.

I have a screenshot below

Screenshot 2024-02-05 at 4 50 03 PM
VitalySvyatyuk commented 4 months ago

Thanks for a Fractal indicator, I never used it before. I updated po_bot_indicators.py script with MA1 + MA2 + Fractal conditions. By tests, it works well with 1 and 5 minutes, and for OTC and non-OTC results are the same. Fractal alone shows the same good results.

x-ender commented 4 months ago

That is great. I was able to code it as well. Thanks for looking into it.. Let me see how handled the Fractal because the library didn't really make it simple to know if the last indication was red or green.

VitalySvyatyuk commented 4 months ago

To have the last value of a Fractal, use this function:

def last_fractal(fractal):
    for i in range(1, len(fractal) - 1):
        if fractal[-i].fractal_bear:
            return 'bear'
        elif fractal[-i].fractal_bull:
            return 'bull'
    return ''

and then add to the condition: and last_fractal(fractal) == 'bear':

Waldi2130 commented 4 months ago

Hello, could you tell me if it is possible to get the moment of closing of a candle or opening of a new candle to bet at the moment of opening of a new candle. Thank you.

x-ender commented 4 months ago

To have the last value of a Fractal, use this function:

def last_fractal(fractal):
    for i in range(1, len(fractal) - 1):
        if fractal[-i].fractal_bear:
            return 'bear'
        elif fractal[-i].fractal_bull:
            return 'bull'
    return ''

and then add to the condition: and last_fractal(fractal) == 'bear':

Thank you

VitalySvyatyuk commented 4 months ago

@Waldi2130 everything inside check_indicators() function happening exactly on the old candle closing. On line 182 of po_bot_indicators.py you may see a condition if tstamp % PERIOD == 0:. So, if the tstamp is divided by 60 without a reminder, that means that the candle is closing right now.

Waldi2130 commented 4 months ago

Thank you. I am still trying to understand this code, it writes that it works and outputs the currency pair, but already as half an hour does not make bets, so I'm still watching its work.

VitalySvyatyuk commented 4 months ago

@Waldi2130 update a condition on lines 124 and 126 to:

    if fractal[-1].fractal_bear:
        do_action('put')
    elif fractal[-1].fractal_bull:
        do_action('call')
Waldi2130 commented 4 months ago

Yes, I tried to do this and tried to log the last_fractal function, but it does not output the fractal, as if it does not see it. Although there are no errors during operation, I also tried to remove the check for fractal and leave only sma, according to sma it only processes calls, while I’m still trying to figure it out. I work at 1 minute, everything below gives an error when receiving candles.

Waldi2130 commented 4 months ago

If I'm not mistaken, he is looking for a fractal that opened on the previous candle, if so, then I understand why I have a long time empty, he just hasn't found it yet. Either something really doesn't work for me.

x-ender commented 4 months ago

If I'm not mistaken, he is looking for a fractal that opened on the previous candle, if so, then I understand why I have a long time empty, he just hasn't found it yet. Either something really doesn't work for me.

I noticed that fractal[-1].fractal_bear and fractal[-1].fractal_bull returns a 'None' or a value depending on the candle of indication. So i did an iteration of the fractal to get the last two indications and check if the last indication is greater than the second to last indication..

fractal = indicators.get_fractal(quotes) fractal_result = '' fractals = [] for fract in reversed(fractal) : if fract.fractal_bear != None : fractals.append(fract.fractal_bear) elif fract.fractal_bull != None : fractals.append(fract.fractal_bull) if len(fractals) > 1 : break

if len(fractals) > 1 : if fractals[0] < fractals[1] : fractal_result = 'bull' # meaning the last fractal is red and market is going up else : fractal_result = 'bare' # meaning the last fractal is green and market is going down

if fractal_result == 'bull': print(f"Do call option: last fractal is red") do_action('call')

if fractal_result == 'bare': print(f"Do call option: last fractal is green") do_action('put')

x-ender commented 4 months ago

Thanks for a Fractal indicator, I never used it before. I updated po_bot_indicators.py script with MA1 + MA2 + Fractal conditions. By tests, it works well with 1 and 5 minutes, and for OTC and non-OTC results are the same. Fractal alone shows the same good results.

I want to host this bot on a server and make it run by click of a telegram bot button without my computer on or showing the chrome browser on a physical device. But I know this code is designed to run with a physical computer on. I've done a little bit of research on it as i'm new to python and automation. I literally started learning python the day i opened this issue last week. So is there a way to make it log me in when it starts from the hosted server.. maybe taking input from a telegram bot. Is it even possible to host it in a server and it'll work.. still using the Chrome Web Driver. Can you guide me? Please

VitalySvyatyuk commented 4 months ago

@x-ender , this script cannot run as a background process even if you set the option --headless, so you always have the browser opened. And this is not convenient for automatization. For a nice automatization, you should connect to the trading platform with an API (Binance API for example). In that case, all logic will be predefined in the script, which you will be able to start/stop from the Telegram bot. The script can be run as a background process on the server without any display/browser.

x-ender commented 4 months ago

Yeah. I don't mean the code here. I'm modifying it for the server. checking if user has logged in and then logging them in by prompting them to input email and password. Changing the market each time a trade closes. etc. I'm preparing incase it'll be possible to move it to a server

Waldi2130 commented 4 months ago

Hello, thank you for answering. I changed the code and the script has been running for about an hour and a half, but it still does not output the fractal information. Now I am planning to uninstall python completely from my computer and all dependencies to try to install everything from scratch. I don't get any errors when running the script, but no information on the fractal, I connect to the site through a mirror, I tried through the original site, but the situation hasn't changed.

Python 3.12.1 Chromedriver 122.0.6261

x-ender commented 4 months ago

If I'm not mistaken, he is looking for a fractal that opened on the previous candle, if so, then I understand why I have a long time empty, he just hasn't found it yet. Either something really doesn't work for me.

I noticed that fractal[-1].fractal_bear and fractal[-1].fractal_bull returns a 'None' or a value depending on the candle of indication. So i did an iteration of the fractal to get the last two indications and check if the last indication is greater than the second to last indication..

fractal = indicators.get_fractal(quotes) fractal_result = '' fractals = [] for fract in reversed(fractal) : if fract.fractal_bear != None : fractals.append(fract.fractal_bear) elif fract.fractal_bull != None : fractals.append(fract.fractal_bull) if len(fractals) > 1 : break

if len(fractals) > 1 : if fractals[0] < fractals[1] : fractal_result = 'bull' # meaning the last fractal is red and market is going up else : fractal_result = 'bare' # meaning the last fractal is green and market is going down

if fractal_result == 'bull': print(f"Do call option: last fractal is red") do_action('call')

if fractal_result == 'bare': print(f"Do call option: last fractal is green") do_action('put')

Alright. Add these print statements after the elif statement in the for loop

print(fract.date) print('---------') print(fract.fractal_bear) print('---------') print(fract.fractal_bull)

VitalySvyatyuk commented 4 months ago

@Waldi2130 , you can use other indicators that have instant values, like psar or macd etc. Simple condition without any indicators can look like this:

if quotes[-1].close > quotes[-1].open:
    do_action('put')
elif quotes[-1].close < quotes[-1].open:
    do_action('call')
Waldi2130 commented 4 months ago

Если я не ошибаюсь, он ищет фрактал, который открылся на предыдущей свече, если да, то я понимаю почему у меня давно пустой, просто он его еще не нашел. Либо у меня что-то действительно не получается.

Я заметил это и возвращает 'None' или значение в зависимости от свечи индикации. Итак, я сделал итерацию фрактала, чтобы получить последние два показания и проверить, больше ли последнее показание, чем предпоследнее.fractal[-1].fractal_bear``fractal[-1].fractal_bull fractal = indicators.get_fractal(quotes) fractal_result = '' fractals = [] for fract in reversed(fractal) : if fract.fractal_bear != None : fractals.append(fract.fractal_bear) elif fract.fractal_bull != None : fractals.append(fract.fractal_bull) if len(fractals) > 1 : break if len(fractals) > 1 : if fractals[0] < fractals[1] : fractal_result = 'bull' # meaning the last fractal is red and market is going up else : fractal_result = 'bare' # meaning the last fractal is green and market is going down if fractal_result == 'bull': print(f"Do call option: last fractal is red") do_action('call') if fractal_result == 'bare': print(f"Do call option: last fractal is green") do_action('put')

Хорошо. Добавьте эти операторы print после оператора в циклеelif``for

print(fract.date) print('---------') print(fract.fractal_bear) print('---------') print(fract.fractal_bull)

image

To me, it looks like this. Okay, I'll try to switch to other indicators, and paralei

x-ender commented 4 months ago

@Waldi2130 , Yes.. That's how the print result should look. But i only used it to make sure that I'm getting the last two indications of the fractal. Where it prints None, it means that the candle bearing that datetime has no fractal indication on or below it

Waldi2130 commented 4 months ago

@Waldi2130 , Yes.. That's how the print result should look. But i only used it to make sure that I'm getting the last two indications of the fractal. Where it prints None, it means that the candle bearing that datetime has no fractal indication on or below it

that is, we check the fractal on the current candle, not on the last or past candle ?

x-ender commented 4 months ago

@Waldi2130 , Yes.. That's how the print result should look. But i only used it to make sure that I'm getting the last two indications of the fractal. Where it prints None, it means that the candle bearing that datetime has no fractal indication on or below it

that is, we check the fractal on the current candle, not on the last or past candle ?

Remember that print statement is in a for loop that iterates from the last candle to the 'second' candle found to have a fractal indication on or below it

Screenshot 2024-02-07 at 3 32 30 PM
Waldi2130 commented 4 months ago

Да.. Вот так должен выглядеть результат печати. Но я использовал его только для того, чтобы убедиться, что я получаю последние два признака фрактала. Если он печатает None, это означает, что свеча, несущая эту дату и время, не имеет фрактальной индикации на ней или под ней

То есть мы проверяем фрактал на текущей свече, а не на последней или прошедшей свече?

Помните, что оператор print находится в цикле for, который выполняет итерацию от последней свечи ко «второй» свече, на которой или ниже обнаружена фрактальная индикация

Скриншот 2024-02-07 в 3 32 30 PM

I have an assumption that I am not adding new information about candles for stock indicators, because print displays only 10 records from 19:29 to 19:38, although on the chart the time is already 19:45, but print displays only 10 records in a circle. Also, perhaps because of this, stock indicators cannot understand that I had a candle at 19:35 and does not show it.

Waldi2130 commented 4 months ago

image

I moved the indicator check below adding a candle to the list, now it began to display all candles by time. Now I'm waiting to see if it can detect the fractal or not, I hope it works for me.

x-ender commented 4 months ago

@Waldi2130 Oh Okay great.

Waldi2130 commented 4 months ago

@Waldi2130 , you can use other indicators that have instant values, like psar or macd etc. Simple condition without any indicators can look like this:

if quotes[-1].close > quotes[-1].open:
    do_action('put')
elif quotes[-1].close < quotes[-1].open:
    do_action('call')

It doesn't work that way either, it's like it's not receiving these parameters. (((

Waldi2130 commented 4 months ago

@Waldi2130 Oh Okay great.

and are you using windows or mac ?

VitalySvyatyuk commented 4 months ago

@Waldi2130 , you can use other indicators that have instant values, like psar or macd etc. Simple condition without any indicators can look like this:

if quotes[-1].close > quotes[-1].open:
    do_action('put')
elif quotes[-1].close < quotes[-1].open:
    do_action('call')

It doesn't work that way either, it's like it's not receiving these parameters. (((

it's because you moved CANDLES.append() before check_indicators(), so in your last candle open=close=high=low

x-ender commented 4 months ago

@VitalySvyatyuk , I'm trying to change the trade amount and trade time from code. Have you tried it. Please can you help

VitalySvyatyuk commented 4 months ago

@x-ender you can find how to change the amount in po_bot.py file near amount.click() All interaction with buttons is made by Selenium. With Selenium, you specify web element by its CSS selector or by XPath and click. You can debug this with breakpoint() in any place of the code, read about it.

x-ender commented 4 months ago

Thank you. I have been able to get it to change trade time and time frame as well

Waldi2130 commented 4 months ago

I could not find the problem, why half of the indicators do not work, as well as completely empty come fractals and quotes[-1].close, I am also ready to donate if you can successfully solve the problem. By the way, the other day I wanted to send you a donation as a thank you, but I never realized what cryptocurrency address you have specified.

VitalySvyatyuk commented 4 months ago

@Waldi2130 , you can pull the last changes and run the script. It will make an order every minute. I also fixed BTC address for donations.